summaryrefslogtreecommitdiff
path: root/sv.c
diff options
context:
space:
mode:
authorNick Ing-Simmons <nik@tiuk.ti.com>2000-12-12 19:42:13 +0000
committerNick Ing-Simmons <nik@tiuk.ti.com>2000-12-12 19:42:13 +0000
commit511c2ff04fc070a9b9389f53ec595d85ce870c80 (patch)
tree54b7878e53a482196fd27ec5a3475a990c70ab56 /sv.c
parent8a8183332d9a42d93d66e4028ccb28fd2bda82d8 (diff)
parent3601bd2ab5316cf7ceba3f53d5e81474fb7d9b12 (diff)
downloadperl-511c2ff04fc070a9b9389f53ec595d85ce870c80.tar.gz
Integrate/merge mainline with further efficiency tweak to sv.c's utf8 stuff.
p4raw-id: //depot/perlio@8093
Diffstat (limited to 'sv.c')
-rw-r--r--sv.c24
1 files changed, 13 insertions, 11 deletions
diff --git a/sv.c b/sv.c
index e29d1b40cf..7c9c4dbe68 100644
--- a/sv.c
+++ b/sv.c
@@ -2390,36 +2390,37 @@ Convert the PV of an SV to its UTF8-encoded form.
void
Perl_sv_utf8_upgrade(pTHX_ register SV *sv)
{
- char *s, *t;
- int hibit = FALSE;
+ char *s, *t, *e;
+ int hibit = 0;
if (!sv || !SvPOK(sv) || SvUTF8(sv))
return;
/* This function could be much more efficient if we had a FLAG in SVs
* to signal if there are any hibit chars in the PV.
+ * Given that there isn't make loop fast as possible
*/
- for (s = t = SvPVX(sv); t < SvEND(sv) && !hibit; t++) {
- if (*t & 0x80) {
- hibit = TRUE;
+ s = SvPVX(sv);
+ e = SvEND(sv);
+ t = s;
+ while (t < e) {
+ if ((hibit = *t++ & 0x80))
break;
- }
}
if (hibit) {
STRLEN len;
if (SvREADONLY(sv) && SvFAKE(sv)) {
- Perl_warn(aTHX_ "%d s=%p t=%p e=%p",(int)hibit,s,t,SvEND(sv));
- sv_dump(sv);
sv_force_normal(sv);
s = SvPVX(sv);
}
len = SvCUR(sv) + 1; /* Plus the \0 */
SvPVX(sv) = (char*)bytes_to_utf8((U8*)s, &len);
SvCUR(sv) = len - 1;
+ if (SvLEN(sv) != 0)
+ Safefree(s); /* No longer using what was there before. */
SvLEN(sv) = len; /* No longer know the real size. */
SvUTF8_on(sv);
- Safefree(s); /* No longer using what was there before. */
}
}
@@ -2482,6 +2483,7 @@ Perl_sv_utf8_decode(pTHX_ register SV *sv)
{
if (SvPOK(sv)) {
char *c;
+ char *e;
bool has_utf = FALSE;
if (!sv_utf8_downgrade(sv, TRUE))
return FALSE;
@@ -2492,8 +2494,8 @@ Perl_sv_utf8_decode(pTHX_ register SV *sv)
c = SvPVX(sv);
if (!is_utf8_string((U8*)c, SvCUR(sv)+1))
return FALSE;
-
- while (c < SvEND(sv)) {
+ e = SvEND(sv);
+ while (c < e) {
if (*c++ & 0x80) {
SvUTF8_on(sv);
break;