Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

possible to precompile regexps

135 views
Skip to first unread message

Svenn Are Bjerkem

unread,
Nov 4, 2004, 8:56:50 AM11/4/04
to
Hi,
I am using a lot of regsub and regexp to tune my data. I am wondering if
it is possible to "precompile" a regexp for later use as I let many
small regsubs scan and modify the data. I hope for some performance
improvement, but maybe this has already been taken care of inside tcl.
--
Svenn

Helmut Giese

unread,
Nov 4, 2004, 10:58:44 AM11/4/04
to

Hi Svenn,
AFAIRC the Tcl core caches the last 30 REs it compiled. You can
#define the respective value to a number suitable to you and recompile
Tcl to cache as many compiled REs as you like.
Maybe one of the core gurus will add further info.
HTH
Helmut Giese

Michael Schlenker

unread,
Nov 4, 2004, 11:41:07 AM11/4/04
to

The regexp are cached dynamically, and if you use a variable to store
the regexp and do not modify it, the compiled regexp is stored in the
var for further use.

Michael

Helmut Giese

unread,
Nov 4, 2004, 4:11:11 PM11/4/04
to
On Thu, 04 Nov 2004 17:41:07 +0100, Michael Schlenker
<sch...@uni-oldenburg.de> wrote:

Hi Michael,


>The regexp are cached dynamically, and if you use a variable to store
>the regexp and do not modify it, the compiled regexp is stored in the
>var for further use.

sounds interesting, but a piece or two are missing.
Say I define my pattern like
set re {^\s*#\s*pragma\s+(.)}
(to find #pragma <something> statements). I would use it like
if { [regexp $re $line -> rest] }
But where is the compiled version stored ? Certainly not in 're', or
is it?
Thanks for any insight and best regards
Helmut Giese

David Gravereaux

unread,
Nov 4, 2004, 4:12:12 PM11/4/04
to
hgi...@ratiosoft.com (Helmut Giese) wrote:

Stored compiled in the Tcl_Obj* after it is first run, just like bytecode.
--
David Gravereaux <davy...@pobox.com>
[species: human; planet: earth,milkyway(western spiral arm),alpha sector]

Gerald W. Lester

unread,
Nov 4, 2004, 8:47:44 PM11/4/04
to
Helmut Giese wrote:

Yes, it is stored in re, the Tcl_Obj is a "compiled regular expression"
type (plus of course the string representation).

--
+--------------------------------+---------------------------------------+
| Gerald W. Lester | "The man who fights for his ideals is |
| Gerald...@cox.net | the man who is alive." -- Cervantes |
+--------------------------------+---------------------------------------+

Svenn Are Bjerkem

unread,
Nov 5, 2004, 3:22:45 AM11/5/04
to
Hi,

I extended http://wiki.tcl.tk/986 with what I think was core info in
this thread. If you disagree, please edit the entry to your liking. I
found this info very useful.

--
Svenn

Helmut Giese

unread,
Nov 5, 2004, 7:01:39 AM11/5/04
to
On Thu, 04 Nov 2004 13:12:12 -0800, David Gravereaux
<davy...@pobox.com> wrote:

>>But where is the compiled version stored ? Certainly not in 're', or
>>is it?
>>Thanks for any insight and best regards
>>Helmut Giese
>
>Stored compiled in the Tcl_Obj* after it is first run, just like bytecode.

Thanks David,
this is an interesting piece of information. Should I ever do heavy RE
stuff, I'll put all my REs into a (global) array. Neat.
Q: Why didn't I know this?
A: Because I don't regularly study the Tcl core's source files ... (or
would there have been some other source of information in this case?)
Best regards
Helmut Giese

Markus Elfring

unread,
Nov 6, 2004, 8:16:22 AM11/6/04
to
> A: Because I don't regularly study the Tcl core's source files ... (or
> would there have been some other source of information in this case?)

Please look at these articles.
- http://mini.net/tcl/2244
- http://wiki.tcl.tk/regexp

Helmut Giese

unread,
Nov 6, 2004, 10:17:55 AM11/6/04
to
On 6 Nov 2004 05:16:22 -0800, Markus....@web.de (Markus Elfring)
wrote:

Very interesting. Thanks for the link.
So many useful information ...
Helmut Giese

Svenn Are Bjerkem

unread,
Nov 8, 2004, 2:36:22 AM11/8/04
to

Don't forget that the info on precompilation of regexp in
http://wiki.tcl.tk/regexp was added after this thread was started, so
you wouldn't have had that info without the thread. (Which is why the
thread is referenced)

Kind regards,
--
Svenn

0 new messages