emacs-devel
[Top][All Lists]
Advanced

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

Re: Make regexp handling more regular


From: Stefan Monnier
Subject: Re: Make regexp handling more regular
Date: Thu, 03 Dec 2020 10:10:06 -0500
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/28.0.50 (gnu/linux)

> Off-list, it's been pointed out that the current implementation of
> functions like re-search-forward would be faster than these interfaces
> because they produce less garbage -- since there's just one global match
> object, it's static, while

Yes, it's indeed my main worry.
Reusing the match-data sounds like a good practical approach.

Maybe another approach would be to use an API where the match doesn't
return a "match data" but instead let-binds some variables with the
relevant data.  IOW, specify right away in which part of the data you're
interested, so only the relevant data is returned.  That would also
remove the need for the `string-match-p` alternatives which don't return
any match data.

I'm not completely sure what it would look like, tho.  Maybe

    (let-re-match (overall (beg end)) (re-match "regexp")
      ...)

which would be equivalent to

    (progn
      (re-match "regexp")
      (let ((overall (match-string 0))
            (beg (match-beginning 1))
            (end (match-end 1)))
        ...))

??

This has problems dealing with match-failure tho: it works, but it with
a lot of spurious match-data extraction.


        Stefan




reply via email to

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