summaryrefslogtreecommitdiff
path: root/pp.c
diff options
context:
space:
mode:
authorNicholas Clark <nick@ccl4.org>2008-01-02 23:41:21 +0000
committerNicholas Clark <nick@ccl4.org>2008-01-02 23:41:21 +0000
commit740cce10afff4bec3346f61ab3d0f7bfa424948c (patch)
tree83c031300e2326e8d8ae399e088c4d3a42472a13 /pp.c
parente350b669f3dadb9da757b62a20659cbc7eca2190 (diff)
downloadperl-740cce10afff4bec3346f61ab3d0f7bfa424948c.tar.gz
Add a new function newSVpvn_flags(), which takes a third parameter of
flag bits. Right now the only flag bit is SVf_UTF8, which will call SvUTF8_on() on the new SV for you. Provide a wrapper newSVpvn_utf8(), which takes a boolean, and passes in SVf_UTF8 if that is true. Refactor the core to use it where possible. It makes the source code clearer and smaller, but seems to be swings and roundabouts on object code size. p4raw-id: //depot/perl@32807
Diffstat (limited to 'pp.c')
-rw-r--r--pp.c39
1 files changed, 10 insertions, 29 deletions
diff --git a/pp.c b/pp.c
index 78e0e367c6..3ac702db9a 100644
--- a/pp.c
+++ b/pp.c
@@ -3312,9 +3312,7 @@ PP(pp_index)
Otherwise I need to avoid calls to sv_pos_u2b(), which (dangerously)
will trigger magic and overloading again, as will fbm_instr()
*/
- big = sv_2mortal(newSVpvn(big_p, biglen));
- if (big_utf8)
- SvUTF8_on(big);
+ big = sv_2mortal(newSVpvn_utf8(big_p, biglen, big_utf8));
big_p = SvPVX(big);
}
if (SvGAMAGIC(little) || (is_index && !SvOK(little))) {
@@ -3326,9 +3324,7 @@ PP(pp_index)
This is all getting to messy. The API isn't quite clean enough,
because data access has side effects.
*/
- little = sv_2mortal(newSVpvn(little_p, llen));
- if (little_utf8)
- SvUTF8_on(little);
+ little = sv_2mortal(newSVpvn_utf8(little_p, llen, little_utf8));
little_p = SvPVX(little);
}
@@ -4755,11 +4751,9 @@ PP(pp_split)
if (m >= strend)
break;
- dstr = newSVpvn(s, m-s);
+ dstr = newSVpvn_utf8(s, m-s, do_utf8);
if (make_mortal)
sv_2mortal(dstr);
- if (do_utf8)
- (void)SvUTF8_on(dstr);
XPUSHs(dstr);
/* skip the whitespace found last */
@@ -4788,11 +4782,9 @@ PP(pp_split)
m++;
if (m >= strend)
break;
- dstr = newSVpvn(s, m-s);
+ dstr = newSVpvn_utf8(s, m-s, do_utf8);
if (make_mortal)
sv_2mortal(dstr);
- if (do_utf8)
- (void)SvUTF8_on(dstr);
XPUSHs(dstr);
s = m;
}
@@ -4817,12 +4809,11 @@ PP(pp_split)
/* keep track of how many bytes we skip over */
m = s;
s += UTF8SKIP(s);
- dstr = newSVpvn(m, s-m);
+ dstr = newSVpvn_utf8(m, s-m, TRUE);
if (make_mortal)
sv_2mortal(dstr);
- (void)SvUTF8_on(dstr);
PUSHs(dstr);
if (s >= strend)
@@ -4859,11 +4850,9 @@ PP(pp_split)
;
if (m >= strend)
break;
- dstr = newSVpvn(s, m-s);
+ dstr = newSVpvn_utf8(s, m-s, do_utf8);
if (make_mortal)
sv_2mortal(dstr);
- if (do_utf8)
- (void)SvUTF8_on(dstr);
XPUSHs(dstr);
/* The rx->minlen is in characters but we want to step
* s ahead by bytes. */
@@ -4878,11 +4867,9 @@ PP(pp_split)
(m = fbm_instr((unsigned char*)s, (unsigned char*)strend,
csv, multiline ? FBMrf_MULTILINE : 0)) )
{
- dstr = newSVpvn(s, m-s);
+ dstr = newSVpvn_utf8(s, m-s, do_utf8);
if (make_mortal)
sv_2mortal(dstr);
- if (do_utf8)
- (void)SvUTF8_on(dstr);
XPUSHs(dstr);
/* The rx->minlen is in characters but we want to step
* s ahead by bytes. */
@@ -4913,11 +4900,9 @@ PP(pp_split)
strend = s + (strend - m);
}
m = RX_OFFS(rx)[0].start + orig;
- dstr = newSVpvn(s, m-s);
+ dstr = newSVpvn_utf8(s, m-s, do_utf8);
if (make_mortal)
sv_2mortal(dstr);
- if (do_utf8)
- (void)SvUTF8_on(dstr);
XPUSHs(dstr);
if (RX_NPARENS(rx)) {
I32 i;
@@ -4929,14 +4914,12 @@ PP(pp_split)
parens that didn't match -- they should be set to
undef, not the empty string */
if (m >= orig && s >= orig) {
- dstr = newSVpvn(s, m-s);
+ dstr = newSVpvn_utf8(s, m-s, do_utf8);
}
else
dstr = &PL_sv_undef; /* undef, not "" */
if (make_mortal)
sv_2mortal(dstr);
- if (do_utf8)
- (void)SvUTF8_on(dstr);
XPUSHs(dstr);
}
}
@@ -4951,11 +4934,9 @@ PP(pp_split)
/* keep field after final delim? */
if (s < strend || (iters && origlimit)) {
const STRLEN l = strend - s;
- dstr = newSVpvn(s, l);
+ dstr = newSVpvn_utf8(s, l, do_utf8);
if (make_mortal)
sv_2mortal(dstr);
- if (do_utf8)
- (void)SvUTF8_on(dstr);
XPUSHs(dstr);
iters++;
}