[s2] regexp cleanup
[commit: http://hg.dwscoalition.org/s2/rev/d9c442fda58a]
http://bugs.dwscoalition.org/show_bug.cgi?id=2792
Avoid regular expression syntax which can negatively impact performance.
Codemerge from LJ; adapted for Dreamwidth by
kareila.
Files modified:
http://bugs.dwscoalition.org/show_bug.cgi?id=2792
Avoid regular expression syntax which can negatively impact performance.
Codemerge from LJ; adapted for Dreamwidth by
Files modified:
- S2/Tokenizer.pm
--------------------------------------------------------------------------------
diff -r 99d752ac765f -r d9c442fda58a S2/Tokenizer.pm
--- a/S2/Tokenizer.pm Mon Jun 07 03:03:57 2010 +0000
+++ b/S2/Tokenizer.pm Sat Sep 11 09:41:19 2010 -0500
@@ -148,8 +148,8 @@ sub makeToken # () method private : Toke
}
}
- if ($$c =~ /\G\s+/gc) {
- my $ws = $&;
+ if ( $$c =~ /\G(\s+)/gc ) {
+ my $ws = $1;
return S2::TokenWhitespace->new($ws);
}
@@ -157,8 +157,8 @@ sub makeToken # () method private : Toke
return S2::TokenPunct->new($1);
}
- if ($$c =~ /\G[a-zA-Z\_]\w*/gc) {
- my $ident = $&;
+ if ( $$c =~ /\G([a-zA-Z\_]\w*)/gc ) {
+ my $ident = $1;
return S2::TokenIdent->new($ident);
}
@@ -167,12 +167,12 @@ sub makeToken # () method private : Toke
return S2::TokenIntegerLiteral->new($iv);
}
- if ($$c =~ /\G\#.*\n?/gc) {
- return S2::TokenComment->new($&);
+ if ( $$c =~ /\G(\#.*\n?)/gc ) {
+ return S2::TokenComment->new( $1 );
}
- if ($$c =~ /.+/gc) {
- S2::error($this->getPos(), "Parse error! Unknown token. ($&)");
+ if ( $$c =~ /(.+)/gc ) {
+ S2::error( $this->getPos(), "Parse error! Unknown token. ($1)" );
}
return undef;
--------------------------------------------------------------------------------
