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.
if (!PerlLIO_fstat(PerlIO_fileno(fp), &st) && S_ISREG(st.st_mode)) {
const Off_t offset = PerlIO_tell(fp);
if (offset != (Off_t) -1 && st.st_size + append > offset) {
- (void) SvGROW(sv, (STRLEN)((st.st_size - offset) + append + 1));
+ (void) SvGROW(sv, (STRLEN)((st.st_size - offset) + append + 1
+#ifdef PERL_NEW_COPY_ON_WRITE
+ /* Add an extra byte for the sake of copy-on-
+ write's buffer reference count. */
+ + 1
+#endif
+ ));
}
}
rsptr = NULL;