summaryrefslogtreecommitdiff
path: root/sv.c
diff options
context:
space:
mode:
authorJan Dubois <jand@activestate.com>1999-05-07 02:59:54 +0200
committerGurusamy Sarathy <gsar@cpan.org>1999-05-10 11:28:30 +0000
commit50483b2ce6766412cfaa60f7a33b2255ab27bf44 (patch)
tree054100c34d3efea79db823d2fa5d94aec50b5f61 /sv.c
parentc850101c1434ba808f7a47c4890caf49ffa3d853 (diff)
downloadperl-50483b2ce6766412cfaa60f7a33b2255ab27bf44.tar.gz
Re: Using existing memory for an SV's PV
Message-ID: <373318ae.19292461@smtp1.ibm.net> p4raw-id: //depot/perl@3375
Diffstat (limited to 'sv.c')
-rw-r--r--sv.c14
1 files changed, 11 insertions, 3 deletions
diff --git a/sv.c b/sv.c
index 5772954c68..463359e0a7 100644
--- a/sv.c
+++ b/sv.c
@@ -2061,7 +2061,8 @@ sv_setsv(SV *dstr, register SV *sstr)
}
if (SvPVX(dstr)) {
(void)SvOOK_off(dstr); /* backoff */
- Safefree(SvPVX(dstr));
+ if (SvLEN(dstr))
+ Safefree(SvPVX(dstr));
SvLEN(dstr)=SvCUR(dstr)=0;
}
}
@@ -2098,7 +2099,7 @@ sv_setsv(SV *dstr, register SV *sstr)
SvFLAGS(dstr) &= ~SVf_OOK;
Safefree(SvPVX(dstr) - SvIVX(dstr));
}
- else
+ else if (SvLEN(dstr))
Safefree(SvPVX(dstr));
}
(void)SvPOK_only(dstr);
@@ -2227,7 +2228,7 @@ sv_usepvn(register SV *sv, register char *ptr, register STRLEN len)
return;
}
(void)SvOOK_off(sv);
- if (SvPVX(sv))
+ if (SvPVX(sv) && SvLEN(sv))
Safefree(SvPVX(sv));
Renew(ptr, len+1, char);
SvPVX(sv) = ptr;
@@ -2273,6 +2274,13 @@ sv_chop(register SV *sv, register char *ptr) /* like set but assuming ptr is in
sv_upgrade(sv,SVt_PVIV);
if (!SvOOK(sv)) {
+ if (!SvLEN(sv)) { /* make copy of shared string */
+ char *pvx = SvPVX(sv);
+ STRLEN len = SvCUR(sv);
+ SvGROW(sv, len + 1);
+ Move(pvx,SvPVX(sv),len,char);
+ *SvEND(sv) = '\0';
+ }
SvIVX(sv) = 0;
SvFLAGS(sv) |= SVf_OOK;
}