summaryrefslogtreecommitdiff
path: root/sv.c
diff options
context:
space:
mode:
authorNicholas Clark <nick@ccl4.org>2010-07-12 11:16:41 +0100
committerNicholas Clark <nick@ccl4.org>2010-07-12 13:43:19 +0100
commitec49a12ce17d116f4e9bda1c3d385aad560ec655 (patch)
tree25e993a1ef7d2d79564837a3cc4eb60501a52b7b /sv.c
parent634d6919699655c843f8d8c3ea64922d0403c499 (diff)
downloadperl-ec49a12ce17d116f4e9bda1c3d385aad560ec655.tar.gz
Break S_utf8_mg_len_cache_update() out from Perl_sv_len_utf8().
Diffstat (limited to 'sv.c')
-rw-r--r--sv.c34
1 files changed, 21 insertions, 13 deletions
diff --git a/sv.c b/sv.c
index 3e99d9c1e4..a3bc6e18a2 100644
--- a/sv.c
+++ b/sv.c
@@ -6065,19 +6065,7 @@ Perl_sv_len_utf8(pTHX_ register SV *const sv)
}
else {
ulen = Perl_utf8_length(aTHX_ s, s + len);
- if (!SvREADONLY(sv)) {
- if (!mg && (SvTYPE(sv) < SVt_PVMG ||
- !(mg = mg_find(sv, PERL_MAGIC_utf8)))) {
- mg = sv_magicext(sv, 0, PERL_MAGIC_utf8,
- &PL_vtbl_utf8, 0, 0);
- }
- assert(mg);
- mg->mg_len = ulen;
- /* For now, treat "overflowed" as "still unknown".
- See RT #72924. */
- if (ulen != (STRLEN) mg->mg_len)
- mg->mg_len = -1;
- }
+ utf8_mg_len_cache_update(sv, &mg, ulen);
}
return ulen;
}
@@ -6358,6 +6346,26 @@ Perl_sv_pos_u2b(pTHX_ register SV *const sv, I32 *const offsetp, I32 *const lenp
}
}
+static void
+S_utf8_mg_len_cache_update(pTHX_ SV *const sv, MAGIC **const mgp,
+ const STRLEN ulen)
+{
+ PERL_ARGS_ASSERT_UTF8_MG_LEN_CACHE_UPDATE;
+ if (SvREADONLY(sv))
+ return;
+
+ if (!*mgp && (SvTYPE(sv) < SVt_PVMG ||
+ !(*mgp = mg_find(sv, PERL_MAGIC_utf8)))) {
+ *mgp = sv_magicext(sv, 0, PERL_MAGIC_utf8, &PL_vtbl_utf8, 0, 0);
+ }
+ assert(*mgp);
+
+ (*mgp)->mg_len = ulen;
+ /* For now, treat "overflowed" as "still unknown". See RT #72924. */
+ if (ulen != (STRLEN) (*mgp)->mg_len)
+ (*mgp)->mg_len = -1;
+}
+
/* Create and update the UTF8 magic offset cache, with the proffered utf8/
byte length pairing. The (byte) length of the total SV is passed in too,
as blen, because for some (more esoteric) SVs, the call to SvPV_const()