diff options
author | Nick Ing-Simmons <nik@tiuk.ti.com> | 2000-12-12 19:42:13 +0000 |
---|---|---|
committer | Nick Ing-Simmons <nik@tiuk.ti.com> | 2000-12-12 19:42:13 +0000 |
commit | 511c2ff04fc070a9b9389f53ec595d85ce870c80 (patch) | |
tree | 54b7878e53a482196fd27ec5a3475a990c70ab56 | |
parent | 8a8183332d9a42d93d66e4028ccb28fd2bda82d8 (diff) | |
parent | 3601bd2ab5316cf7ceba3f53d5e81474fb7d9b12 (diff) | |
download | perl-511c2ff04fc070a9b9389f53ec595d85ce870c80.tar.gz |
Integrate/merge mainline with further efficiency tweak to sv.c's utf8 stuff.
p4raw-id: //depot/perlio@8093
-rw-r--r-- | lib/File/DosGlob.pm | 49 | ||||
-rw-r--r-- | sv.c | 24 |
2 files changed, 62 insertions, 11 deletions
diff --git a/lib/File/DosGlob.pm b/lib/File/DosGlob.pm index 3401b5fe9e..2b4d39acd0 100644 --- a/lib/File/DosGlob.pm +++ b/lib/File/DosGlob.pm @@ -1,5 +1,8 @@ #!perl -w +# use strict fails +#Can't use string ("main::glob") as a symbol ref while "strict refs" in use at /usr/lib/perl5/5.005/File/DosGlob.pm line 191. + # # Documentation at the __END__ # @@ -116,6 +119,52 @@ sub glob { push @pat, $pat; } + # Mike Mestnik: made to do abc{1,2,3} == abc1 abc2 abc3. + # abc3 will be the original {3} (and drop the {}). + # abc1 abc2 will be put in @appendpat. + # This was just the esiest way, not nearly the best. + REHASH: { + my @appendpat = (); + for (@pat) { + # There must be a "," I.E. abc{efg} is not what we want. + while ( /^(.*)(?<!\\)\{(.*?)(?<!\\)\,.*?(?<!\\)\}(.*)$/ ) { + my ($start, $match, $end) = ($1, $2, $3); + #print "Got: \n\t$start\n\t$match\n\t$end\n"; + my $tmp = "$start$match$end"; + while ( $tmp =~ s/^(.*?)(?<!\\)\{(?:.*(?<!\\)\,)?(.*\Q$match\E.*?)(?:(?<!\\)\,.*)?(?<!\\)\}(.*)$/$1$2$3/ ) { + #print "Striped: $tmp\n"; + # these expanshions will be preformed by the original, + # when we call REHASH. + } + push @appendpat, ("$tmp"); + s/^\Q$start\E(?<!\\)\{\Q$match\E(?<!\\)\,/$start\{/; + if ( /^\Q$start\E(?<!\\)\{(?!.*?(?<!\\)\,.*?\Q$end\E$)(.*)(?<!\\)\}\Q$end\E$/ ) { + $match = $1; + #print "GOT: \n\t$start\n\t$match\n\t$end\n\n"; + $_ = "$start$match$end"; + } + } + #print "Sould have "GOT" vs "Got"!\n"; + #FIXME: There should be checking for this. + # How or what should be done about failure is beond me. + } + if ( $#appendpat != -1 + ) { + #print "LOOP\n"; + #FIXME: Max loop, no way! :") + for ( @appendpat ) { + push @pat, $_; + } + goto REHASH; + } + } + for ( @pat ) { + s/\\{/{/g; + s/\\}/}/g; + s/\\,/,/g; + } + #print join ("\n", @pat). "\n"; + # assume global context if not provided one $cxix = '_G_' unless defined $cxix; $iter{$cxix} = 0 unless exists $iter{$cxix}; @@ -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; |