all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: David Kastrup <dak@gnu.org>
Cc: "Mark A. Hershberger" <mah@everybody.org>, emacs-devel@gnu.org
Subject: Re: Inefficient code in xml.el
Date: Mon, 06 Jun 2005 14:02:41 +0200	[thread overview]
Message-ID: <8564wr8zha.fsf@lola.goethe.zz> (raw)
In-Reply-To: <m364wrog8y.fsf@kfs-l.imdomain.dk> (Kim F. Storm's message of "Mon, 06 Jun 2005 13:51:25 +0200")

storm@cua.dk (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	other threads:[~2005-06-06 12:02 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2005-06-06 11:51 Inefficient code in xml.el Kim F. Storm
2005-06-06 12:02 ` David Kastrup [this message]
  -- strict thread matches above, loose matches on Subject: below --
2005-06-06 12:41 klaus.berndl
2005-06-06 17:18 ` Kevin Rodgers

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=8564wr8zha.fsf@lola.goethe.zz \
    --to=dak@gnu.org \
    --cc=emacs-devel@gnu.org \
    --cc=mah@everybody.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this external index

	https://git.savannah.gnu.org/cgit/emacs.git
	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.