summaryrefslogtreecommitdiff
path: root/sv.c
diff options
context:
space:
mode:
authorJarkko Hietaniemi <jhi@iki.fi>2000-09-14 22:40:38 +0000
committerJarkko Hietaniemi <jhi@iki.fi>2000-09-14 22:40:38 +0000
commit40826f67d31c2606453337361c7fd592c5548941 (patch)
treea281d3f38ff775df997d05d02a1eedc9fa4ee4fe /sv.c
parent9f9ab9055319ce9b1a2b147cb13f3474dcc9c3b7 (diff)
downloadperl-40826f67d31c2606453337361c7fd592c5548941.tar.gz
We don't need to count the high bit bytes, a boolean is enough.
p4raw-id: //depot/perl@7086
Diffstat (limited to 'sv.c')
-rw-r--r--sv.c21
1 files changed, 9 insertions, 12 deletions
diff --git a/sv.c b/sv.c
index 039e7d6bc5..a89c49a68b 100644
--- a/sv.c
+++ b/sv.c
@@ -2396,28 +2396,25 @@ Convert the PV of an SV to its UTF8-encoded form.
void
Perl_sv_utf8_upgrade(pTHX_ register SV *sv)
{
- int hicount;
- char *c;
- char *s;
+ char *s, *t;
+ bool hibit;
if (!sv || !SvPOK(sv) || SvUTF8(sv))
return;
- /* This function could be much more efficient if we had a FLAG
- * to signal if there are any hibit chars in the string
+ /* 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.
*/
- hicount = 0;
- for (c = s = SvPVX(sv); c < SvEND(sv); c++) {
- if (*c & 0x80)
- hicount++;
- }
+ for (s = t = SvPVX(sv), hibit = FALSE; t < SvEND(sv) && !hibit; t++)
+ if (*t & 0x80)
+ hibit = TRUE;
- if (hicount) {
+ if (hibit) {
STRLEN len = SvCUR(sv) + 1; /* Plus the \0 */
SvPVX(sv) = (char*)bytes_to_utf8((U8*)s, &len);
SvCUR(sv) = len - 1;
- Safefree(s); /* No longer using what was there before */
SvUTF8_on(sv);
+ Safefree(s); /* No longer using what was there before */
}
}