unofficial mirror of emacs-devel@gnu.org 
 help / color / mirror / code / Atom feed
From: <klaus.berndl@sdm.de>
Cc: mah@everybody.org, emacs-devel@gnu.org
Subject: RE: Inefficient code in xml.el
Date: Mon, 6 Jun 2005 14:41:46 +0200	[thread overview]
Message-ID: <A47B192B0358794C958615D788BF7FB7ACB3E3@mucmail1.sdm.de> (raw)

Well, i get the point, but how an elisp-programmer should know this?!

The manual says:

 - Function: match-data
     This function returns a newly constructed list containing all the
     information on what text the last search matched.  Element zero is
     the position of the beginning of the match for the whole
     expression; element one is the position of the end of the match
     for the expression.  The next two elements are the positions of
     the beginning and end of the match for the first subexpression,
     and so on.  In general, element number 2N corresponds to
     `(match-beginning N)'; and element number 2N + 1 corresponds to
     `(match-end N)'.

     All the elements are markers or `nil' if matching was done on a
     buffer, and all are integers or `nil' if matching was done on a
     string with `string-match'.

     As always, there must be no possibility of intervening searches
     between the call to a search function and the call to `match-data'
     that is intended to access the match data for that search.

          (match-data)
               =>  (#<marker at 9 in foo>
                    #<marker at 17 in foo>
                    #<marker at 13 in foo>
                    #<marker at 17 in foo>)

What about to mention such inefficiency-problems in the documentation?!
The manual only says "... Corresponds to ....". IMHO the documentation
must mention the performnace-topic if it is so important you wrote in
these postings!

Ciao,
Klaus


David Kastrup wrote:
> 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!

             reply	other threads:[~2005-06-06 12:41 UTC|newest]

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

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

  List information: https://www.gnu.org/software/emacs/

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

  git send-email \
    --in-reply-to=A47B192B0358794C958615D788BF7FB7ACB3E3@mucmail1.sdm.de \
    --to=klaus.berndl@sdm.de \
    --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 public inbox

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

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).