emacs-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Inefficient code in xml.el


From: David Kastrup
Subject: Re: Inefficient code in xml.el
Date: Mon, 06 Jun 2005 14:02:41 +0200
User-agent: Gnus/5.11 (Gnus v5.11) Emacs/22.0.50 (gnu/linux)

address@hidden (Kim F. Storm) writes:

> I noticed that xml.el has several occurences of code like this:
>
>          ((looking-at (concat "<!ENTITY[ \t\n\r]*\\(" xml-name-re
>                               "\\)[ \t\n\r]*\\(" xml-entity-value-re
>                               "\\)[ \t\n\r]*>"))
>           (let ((name  (buffer-substring (nth 2 (match-data))
>                                          (nth 3 (match-data))))
>                 (value (buffer-substring (+ (nth 4 (match-data)) 1)
>                                          (- (nth 5 (match-data)) 1))))
>             (goto-char (nth 1 (match-data)))
>
>
> Using (match-data) like that is VERY, VERY inefficient.

Uh, that is only half the story.  It is not just devastatingly
inefficient by itself.  Every single such call creates a whole slew of
markers, and those slow down _any_ text manipulation in the buffer
_afterwards_ until they get garbage-collected at some indeterminate
point of time in the future.

The code passage above creates 30 new markers _every_ time it is run.
All of these are maintained for every insertion/deletion in the buffer
until garbage collection finally removes them.

> Use either match-beginning/match-end, or match-string instead.

Yes, yes, YES!

-- 
David Kastrup, Kriemhildstr. 15, 44793 Bochum




reply via email to

[Prev in Thread] Current Thread [Next in Thread]