This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
[perl #121259] Always allow COW after $input=<>
authorFather Chrysostomos <sprout@cpan.org>
Mon, 17 Feb 2014 06:25:27 +0000 (22:25 -0800)
committerFather Chrysostomos <sprout@cpan.org>
Sat, 22 Feb 2014 14:20:02 +0000 (06:20 -0800)
commitdca36a0cc0663875200afd26d6396a4bd3f4736e
tree01712e3be4653f34732080bc5870d1cdb64b13b1
parent591cc29275ca89af0933d32727b40e5162cd19c1
[perl #121259] Always allow COW after $input=<>

sv_grow provides an extra byte for the sake of copy-on-write’s buffer
reference count, but skips this for multiples of 256 (though the com-
ments there say powers of two).

When we do

    $input=<>

The assignment is optimised away and the allocation takes place in
sv_gets.  In that code path, we know we don’t need a nice power of
two and allocating an extra byte won’t hurt, so go ahead and add an
extra byte.

This speeds up code doing m//g on $input, because it avoids the pre-
match copy.
sv.c