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
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
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
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]
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 |
+--------------------------------+---------------------------------------+
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
>>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
Please look at these articles.
- http://mini.net/tcl/2244
- http://wiki.tcl.tk/regexp
Very interesting. Thanks for the link.
So many useful information ...
Helmut Giese
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