summaryrefslogtreecommitdiff
path: root/pp_sys.c
diff options
context:
space:
mode:
authorFather Chrysostomos <sprout@cpan.org>2012-10-01 06:28:48 -0700
committerFather Chrysostomos <sprout@cpan.org>2012-10-01 12:51:58 -0700
commit3f9147780a321aebc1c528741373d5c9f9d5c54b (patch)
tree5ef7149b3d2d7a52bcabea5ed92d1e45582061bc /pp_sys.c
parent48a5da33bd0f1ec8d1516f90d3bdf25b24acda6e (diff)
downloadperl-3f9147780a321aebc1c528741373d5c9f9d5c54b.tar.gz
pp_sys.c: Simplify uses of sv_len_utf8
sv_len_utf8 is now careful not to record caches on magical or over- loaded scalars (any non-PV, in fact). It also returns the number of logical characters correctly, regardless of whether its input is utf8. So we can take advantage of that to simplify pp_sysread. For pp_syswrite, we can use sv_or_pv_len_utf8 with the existing string buffer.
Diffstat (limited to 'pp_sys.c')
-rw-r--r--pp_sys.c19
1 files changed, 4 insertions, 15 deletions
diff --git a/pp_sys.c b/pp_sys.c
index 68510f8327..8fb75f5d2d 100644
--- a/pp_sys.c
+++ b/pp_sys.c
@@ -1660,12 +1660,7 @@ PP(pp_sysread)
buffer_utf8 = !IN_BYTES && SvUTF8(bufsv);
}
if (DO_UTF8(bufsv)) {
- /* offset adjust in characters not bytes */
- /* SV's length cache is only safe for non-magical values */
- if (SvGMAGICAL(bufsv))
- blen = utf8_length((const U8 *)buffer, (const U8 *)buffer + blen);
- else
- blen = sv_len_utf8(bufsv);
+ blen = sv_len_utf8_nomg(bufsv);
}
charstart = TRUE;
@@ -1946,15 +1941,9 @@ PP(pp_syswrite)
blen_chars = orig_blen_bytes;
} else {
/* The SV really is UTF-8. */
- if (SvGMAGICAL(bufsv) || SvAMAGIC(bufsv)) {
- /* Don't call sv_len_utf8 again because it will call magic
- or overloading a second time, and we might get back a
- different result. */
- blen_chars = utf8_length((U8*)buffer, (U8*)buffer + blen);
- } else {
- /* It's safe, and it may well be cached. */
- blen_chars = sv_len_utf8(bufsv);
- }
+ /* Don't call sv_len_utf8 on a magical or overloaded
+ scalar, as we might get back a different result. */
+ blen_chars = sv_or_pv_len_utf8(bufsv, buffer, blen);
}
} else {
blen_chars = blen;