develooper Front page | perl.perl5.porters | Postings from January 2014

Why is mother_re *always* set?

Thread Next
January 30, 2014 05:55
Why is mother_re *always* set?
Message ID:
Years ago I added the mother_re member to the regexp structure.

This was designed to work around the fact that we use the regexp
structure to store match results, and in certain situations like
recursive regexps this was leading to corruption.

The idea of the mother_re was that we would do a copy of the base
regexp structure, sharing all of its members between the the copy and
its source. We would then set the "mother_re" value in the child to
point at the parent, and increment the refcount of the parent. Only
when the mother_re is NULL would we actually free various structures
pointed to from the structure.

The result was a fast copy of the regexp, and the ability to have the
same regexp have different match states at the same time.

Today while working on moving extflags to intflags I discovered that
pretty much *any* regexp will have a mother_re.

This is a change I was unaware of, and I wonder why we do it. It seems
like there is no point, and it probably slows things down.

Before I spend a bunch of time debugging this I was wondering if
anybody could shed any light on this. Is it deliberate? If so why?

BTW, at the time I introduced mother_re I mentioned that there is
another, probably better, approach to solving this problem: separate
the match results from the regexp structure itself. Then we dont have
to copy anything, or play refcount games on the regexp structure.
Instead for every match we would just create a new "match" structure
to store the match results (mostly things like the offsets to where
capture buffers start and stop, etc)


perl -Mre=debug -e "/just|another|perl|hacker/"

Thread Next Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at | Group listing | About