|
46 | 46 | char *gconvert(double, int, int, char *);
|
47 | 47 | #endif
|
48 | 48 |
|
| 49 | +#ifdef PERL_NEW_COPY_ON_WRITE |
| 50 | +# ifndef SV_COW_THRESHOLD |
| 51 | +# define SV_COW_THRESHOLD 0 /* COW iff len > K */ |
| 52 | +# endif |
| 53 | +# ifndef SV_COWBUF_THRESHOLD |
| 54 | +# define SV_COWBUF_THRESHOLD 1250 /* COW iff len > K */ |
| 55 | +# endif |
| 56 | +# ifndef SV_COW_MAX_WASTE_THRESHOLD |
| 57 | +# define SV_COW_MAX_WASTE_THRESHOLD 80 /* COW iff (len - cur) < K */ |
| 58 | +# endif |
| 59 | +# ifndef SV_COWBUF_WASTE_THRESHOLD |
| 60 | +# define SV_COWBUF_WASTE_THRESHOLD 80 /* COW iff (len - cur) < K */ |
| 61 | +# endif |
| 62 | +# ifndef SV_COW_MAX_WASTE_FACTOR_THRESHOLD |
| 63 | +# define SV_COW_MAX_WASTE_FACTOR_THRESHOLD 2 /* COW iff len < (cur * K) */ |
| 64 | +# endif |
| 65 | +# ifndef SV_COWBUF_WASTE_FACTOR_THRESHOLD |
| 66 | +# define SV_COWBUF_WASTE_FACTOR_THRESHOLD 2 /* COW iff len < (cur * K) */ |
| 67 | +# endif |
| 68 | +#endif |
| 69 | +/* Work around compiler warnings about unsigned >= THRESHOLD when thres- |
| 70 | + hold is 0. */ |
| 71 | +#if SV_COW_THRESHOLD |
| 72 | +# define GE_COW_THRESHOLD(cur) ((cur) >= SV_COW_THRESHOLD) |
| 73 | +#else |
| 74 | +# define GE_COW_THRESHOLD(cur) 1 |
| 75 | +#endif |
| 76 | +#if SV_COWBUF_THRESHOLD |
| 77 | +# define GE_COWBUF_THRESHOLD(cur) ((cur) >= SV_COWBUF_THRESHOLD) |
| 78 | +#else |
| 79 | +# define GE_COWBUF_THRESHOLD(cur) 1 |
| 80 | +#endif |
| 81 | +#if SV_COW_MAX_WASTE_THRESHOLD |
| 82 | +# define GE_COW_MAX_WASTE_THRESHOLD(cur,len) (((len)-(cur)) < SV_COW_MAX_WASTE_THRESHOLD) |
| 83 | +#else |
| 84 | +# define GE_COW_MAX_WASTE_THRESHOLD(cur,len) 1 |
| 85 | +#endif |
| 86 | +#if SV_COWBUF_WASTE_THRESHOLD |
| 87 | +# define GE_COWBUF_WASTE_THRESHOLD(cur,len) (((len)-(cur)) < SV_COWBUF_WASTE_THRESHOLD) |
| 88 | +#else |
| 89 | +# define GE_COWBUF_WASTE_THRESHOLD(cur,len) 1 |
| 90 | +#endif |
| 91 | +#if SV_COW_MAX_WASTE_FACTOR_THRESHOLD |
| 92 | +# define GE_COW_MAX_WASTE_FACTOR_THRESHOLD(cur,len) ((len) < SV_COW_MAX_WASTE_FACTOR_THRESHOLD * (cur)) |
| 93 | +#else |
| 94 | +# define GE_COW_MAX_WASTE_FACTOR_THRESHOLD(cur,len) 1 |
| 95 | +#endif |
| 96 | +#if SV_COWBUF_WASTE_FACTOR_THRESHOLD |
| 97 | +# define GE_COWBUF_WASTE_FACTOR_THRESHOLD(cur,len) ((len) < SV_COWBUF_WASTE_FACTOR_THRESHOLD * (cur)) |
| 98 | +#else |
| 99 | +# define GE_COWBUF_WASTE_FACTOR_THRESHOLD(cur,len) 1 |
| 100 | +#endif |
| 101 | + |
| 102 | +#define CHECK_COW_THRESHOLD(cur,len) (\ |
| 103 | + GE_COW_THRESHOLD((cur)) && \ |
| 104 | + GE_COW_MAX_WASTE_THRESHOLD((cur),(len)) && \ |
| 105 | + GE_COW_MAX_WASTE_FACTOR_THRESHOLD((cur),(len)) \ |
| 106 | +) |
| 107 | +#define CHECK_COWBUF_THRESHOLD(cur,len) (\ |
| 108 | + GE_COWBUF_THRESHOLD((cur)) && \ |
| 109 | + GE_COWBUF_WASTE_THRESHOLD((cur),(len)) && \ |
| 110 | + GE_COWBUF_WASTE_FACTOR_THRESHOLD((cur),(len)) \ |
| 111 | +) |
49 | 112 | /* void Gconvert: on Linux at least, gcvt (which Gconvert gets deffed to),
|
50 | 113 | * has a mandatory return value, even though that value is just the same
|
51 | 114 | * as the buf arg */
|
@@ -1524,7 +1587,8 @@ Perl_sv_grow(pTHX_ SV *const sv, STRLEN newlen)
|
1524 | 1587 | if (newlen < minlen)
|
1525 | 1588 | newlen = minlen;
|
1526 | 1589 | #ifndef Perl_safesysmalloc_size
|
1527 |
| - newlen = PERL_STRLEN_ROUNDUP(newlen); |
| 1590 | + if (SvLEN(sv)) |
| 1591 | + newlen = PERL_STRLEN_ROUNDUP(newlen); |
1528 | 1592 | #endif
|
1529 | 1593 | if (SvLEN(sv) && s) {
|
1530 | 1594 | s = (char*)saferealloc(s, newlen);
|
@@ -3987,18 +4051,8 @@ S_glob_assign_ref(pTHX_ SV *const dstr, SV *const sstr)
|
3987 | 4051 | return;
|
3988 | 4052 | }
|
3989 | 4053 |
|
3990 |
| -/* Work around compiler warnings about unsigned >= THRESHOLD when thres- |
3991 |
| - hold is 0. */ |
3992 |
| -#if SV_COW_THRESHOLD |
3993 |
| -# define GE_COW_THRESHOLD(len) ((len) >= SV_COW_THRESHOLD) |
3994 |
| -#else |
3995 |
| -# define GE_COW_THRESHOLD(len) 1 |
3996 |
| -#endif |
3997 |
| -#if SV_COWBUF_THRESHOLD |
3998 |
| -# define GE_COWBUF_THRESHOLD(len) ((len) >= SV_COWBUF_THRESHOLD) |
3999 |
| -#else |
4000 |
| -# define GE_COWBUF_THRESHOLD(len) 1 |
4001 |
| -#endif |
| 4054 | + |
| 4055 | + |
4002 | 4056 |
|
4003 | 4057 | #ifdef PERL_DEBUG_READONLY_COW
|
4004 | 4058 | # include <sys/mman.h>
|
@@ -4366,7 +4420,7 @@ Perl_sv_setsv_flags(pTHX_ SV *dstr, SV* sstr, const I32 flags)
|
4366 | 4420 | || ((sflags & (SVs_PADTMP|SVf_READONLY|SVf_IsCOW))
|
4367 | 4421 | == SVs_PADTMP
|
4368 | 4422 | /* whose buffer is worth stealing */
|
4369 |
| - && GE_COWBUF_THRESHOLD(cur) |
| 4423 | + && CHECK_COWBUF_THRESHOLD(cur,len) |
4370 | 4424 | )
|
4371 | 4425 | ) &&
|
4372 | 4426 | !(sflags & SVf_OOK) && /* and not involved in OOK hack? */
|
@@ -4400,14 +4454,14 @@ Perl_sv_setsv_flags(pTHX_ SV *dstr, SV* sstr, const I32 flags)
|
4400 | 4454 | #elif defined(PERL_NEW_COPY_ON_WRITE)
|
4401 | 4455 | (sflags & SVf_IsCOW
|
4402 | 4456 | ? (!len ||
|
4403 |
| - ( (GE_COWBUF_THRESHOLD(cur) || SvLEN(dstr) < cur+1) |
| 4457 | + ( (CHECK_COWBUF_THRESHOLD(cur,len) || SvLEN(dstr) < cur+1) |
4404 | 4458 | /* If this is a regular (non-hek) COW, only so
|
4405 | 4459 | many COW "copies" are possible. */
|
4406 | 4460 | && CowREFCNT(sstr) != SV_COW_REFCNT_MAX ))
|
4407 | 4461 | : ( (sflags & CAN_COW_MASK) == CAN_COW_FLAGS
|
4408 | 4462 | && !(SvFLAGS(dstr) & SVf_BREAK)
|
4409 |
| - && GE_COW_THRESHOLD(cur) && cur+1 < len |
4410 |
| - && (GE_COWBUF_THRESHOLD(cur) || SvLEN(dstr) < cur+1) |
| 4463 | + && CHECK_COW_THRESHOLD(cur,len) && cur+1 < len |
| 4464 | + && (CHECK_COWBUF_THRESHOLD(cur,len) || SvLEN(dstr) < cur+1) |
4411 | 4465 | ))
|
4412 | 4466 | #else
|
4413 | 4467 | sflags & SVf_IsCOW
|
|
0 commit comments