In perl.git, the branch yves/cow_meta has been created
<http://perl5.git.perl.org/perl.git/commitdiff/e0a4a124fcade90c69ad20c040c37eee3a86ab7c?hp=0000000000000000000000000000000000000000>
at e0a4a124fcade90c69ad20c040c37eee3a86ab7c (commit)
- Log -----------------------------------------------------------------
commit e0a4a124fcade90c69ad20c040c37eee3a86ab7c
Author: Yves Orton <[email protected]>
Date: Sun Nov 6 12:19:35 2016 +0100
New COW - Step one, basic COW
Prior to this patch the refcount for COW SVPV's was
stored in the pv buffer at the end of the string after
the NULL.
This meant that the buffer had to be RW, and that it
must be sufficiently overallocated that the refcount
could fit at the end, and less importantly, restricted
the refcount size to 1 byte.
This patch introduces a new struct COW_META which
contains a refcount field, a flags field, and a length
field.
When an SVPV is converted to COW we allocate a new COW_META
structure (out of the HE arena's) and use it to track the
refcount, and the length of the pv buffer (flags are currently
unused but will be used in a follow up patch). The SvLEN
field (actually union) is then used to hold the pointer to
the COW_META structure.
Once a SVPV has a COW_META structure, making a copy requires
simply copying the SvPV, SvCUR, and SvCOW_META structures
and then incrementing the refcount in the COW_META structure,
and setting the IsCOW flag.
The end result of this is that we can now COW any buffer,
overallocated or not, and read-only, or not, at the cost
of more expensive bookkeeping to set up a new COW string.
Step 2 will unify this logic further with the logic
used for refcounted heks in PL_strtab. (Which is where the
flags field comes in.)
Note this implementation is not entirely polished, we could
probably clean some of it up with new macros, etc.
-----------------------------------------------------------------------
--
Perl5 Master Repository