diff options
author | Ian Lance Taylor <ian@gcc.gnu.org> | 2013-11-06 19:49:01 +0000 |
---|---|---|
committer | Ian Lance Taylor <ian@gcc.gnu.org> | 2013-11-06 19:49:01 +0000 |
commit | f038dae646bac2b31be98ab592c0e5206d2d96f5 (patch) | |
tree | 39530b071991b2326f881b2a30a2d82d6c133fd6 /libgo/go/regexp | |
parent | f20f261304993444741e0f0a14d3147e591bc660 (diff) | |
download | gcc-f038dae646bac2b31be98ab592c0e5206d2d96f5.zip gcc-f038dae646bac2b31be98ab592c0e5206d2d96f5.tar.gz gcc-f038dae646bac2b31be98ab592c0e5206d2d96f5.tar.bz2 |
libgo: Update to October 24 version of master library.
From-SVN: r204466
Diffstat (limited to 'libgo/go/regexp')
-rw-r--r-- | libgo/go/regexp/all_test.go | 8 | ||||
-rw-r--r-- | libgo/go/regexp/exec2_test.go | 20 | ||||
-rw-r--r-- | libgo/go/regexp/exec_test.go | 20 | ||||
-rw-r--r-- | libgo/go/regexp/regexp.go | 11 | ||||
-rw-r--r-- | libgo/go/regexp/syntax/doc.go | 8 | ||||
-rw-r--r-- | libgo/go/regexp/syntax/parse.go | 2 | ||||
-rw-r--r-- | libgo/go/regexp/syntax/parse_test.go | 2 | ||||
-rw-r--r-- | libgo/go/regexp/syntax/prog.go | 29 | ||||
-rw-r--r-- | libgo/go/regexp/syntax/prog_test.go | 11 |
9 files changed, 70 insertions, 41 deletions
diff --git a/libgo/go/regexp/all_test.go b/libgo/go/regexp/all_test.go index 9c4d64f..e914a7c 100644 --- a/libgo/go/regexp/all_test.go +++ b/libgo/go/regexp/all_test.go @@ -308,14 +308,14 @@ func TestReplaceAllFunc(t *testing.T) { } actual := re.ReplaceAllStringFunc(tc.input, tc.replacement) if actual != tc.output { - t.Errorf("%q.ReplaceFunc(%q,%q) = %q; want %q", - tc.pattern, tc.input, tc.replacement, actual, tc.output) + t.Errorf("%q.ReplaceFunc(%q,fn) = %q; want %q", + tc.pattern, tc.input, actual, tc.output) } // now try bytes actual = string(re.ReplaceAllFunc([]byte(tc.input), func(s []byte) []byte { return []byte(tc.replacement(string(s))) })) if actual != tc.output { - t.Errorf("%q.ReplaceFunc(%q,%q) = %q; want %q", - tc.pattern, tc.input, tc.replacement, actual, tc.output) + t.Errorf("%q.ReplaceFunc(%q,fn) = %q; want %q", + tc.pattern, tc.input, actual, tc.output) } } } diff --git a/libgo/go/regexp/exec2_test.go b/libgo/go/regexp/exec2_test.go new file mode 100644 index 0000000..7b86b41 --- /dev/null +++ b/libgo/go/regexp/exec2_test.go @@ -0,0 +1,20 @@ +// Copyright 2013 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +// +build !race + +package regexp + +import ( + "testing" +) + +// This test is excluded when running under the race detector because +// it is a very expensive test and takes too long. +func TestRE2Exhaustive(t *testing.T) { + if testing.Short() { + t.Skip("skipping TestRE2Exhaustive during short test") + } + testRE2(t, "testdata/re2-exhaustive.txt.bz2") +} diff --git a/libgo/go/regexp/exec_test.go b/libgo/go/regexp/exec_test.go index 9dfaed7..70d069c 100644 --- a/libgo/go/regexp/exec_test.go +++ b/libgo/go/regexp/exec_test.go @@ -9,7 +9,6 @@ import ( "compress/bzip2" "fmt" "io" - "math/rand" "os" "path/filepath" "regexp/syntax" @@ -67,13 +66,6 @@ func TestRE2Search(t *testing.T) { testRE2(t, "testdata/re2-search.txt") } -func TestRE2Exhaustive(t *testing.T) { - if testing.Short() { - t.Skip("skipping TestRE2Exhaustive during short test") - } - testRE2(t, "testdata/re2-exhaustive.txt.bz2") -} - func testRE2(t *testing.T, file string) { f, err := os.Open(file) if err != nil { @@ -650,11 +642,17 @@ func makeText(n int) []byte { return text[:n] } text = make([]byte, n) + x := ^uint32(0) for i := range text { - if rand.Intn(30) == 0 { + x += x + x ^= 1 + if int32(x) < 0 { + x ^= 0x88888eef + } + if x%31 == 0 { text[i] = '\n' } else { - text[i] = byte(rand.Intn(0x7E+1-0x20) + 0x20) + text[i] = byte(x%(0x7E+1-0x20) + 0x20) } } return text @@ -691,7 +689,7 @@ func BenchmarkMatchEasy1_1K(b *testing.B) { benchmark(b, easy1, 1<<10) } func BenchmarkMatchEasy1_32K(b *testing.B) { benchmark(b, easy1, 32<<10) } func BenchmarkMatchEasy1_1M(b *testing.B) { benchmark(b, easy1, 1<<20) } func BenchmarkMatchEasy1_32M(b *testing.B) { benchmark(b, easy1, 32<<20) } -func BenchmarkMatchMedium_32(b *testing.B) { benchmark(b, medium, 1<<0) } +func BenchmarkMatchMedium_32(b *testing.B) { benchmark(b, medium, 32<<0) } func BenchmarkMatchMedium_1K(b *testing.B) { benchmark(b, medium, 1<<10) } func BenchmarkMatchMedium_32K(b *testing.B) { benchmark(b, medium, 32<<10) } func BenchmarkMatchMedium_1M(b *testing.B) { benchmark(b, medium, 1<<20) } diff --git a/libgo/go/regexp/regexp.go b/libgo/go/regexp/regexp.go index c392b37..0046026 100644 --- a/libgo/go/regexp/regexp.go +++ b/libgo/go/regexp/regexp.go @@ -375,21 +375,18 @@ func (re *Regexp) LiteralPrefix() (prefix string, complete bool) { return re.prefix, re.prefixComplete } -// MatchReader returns whether the Regexp matches the text read by the -// RuneReader. The return value is a boolean: true for match, false for no -// match. +// MatchReader reports whether the Regexp matches the text read by the +// RuneReader. func (re *Regexp) MatchReader(r io.RuneReader) bool { return re.doExecute(r, nil, "", 0, 0) != nil } -// MatchString returns whether the Regexp matches the string s. -// The return value is a boolean: true for match, false for no match. +// MatchString reports whether the Regexp matches the string s. func (re *Regexp) MatchString(s string) bool { return re.doExecute(nil, nil, s, 0, 0) != nil } -// Match returns whether the Regexp matches the byte slice b. -// The return value is a boolean: true for match, false for no match. +// Match reports whether the Regexp matches the byte slice b. func (re *Regexp) Match(b []byte) bool { return re.doExecute(nil, b, "", 0, 0) != nil } diff --git a/libgo/go/regexp/syntax/doc.go b/libgo/go/regexp/syntax/doc.go index bcb5d05..e52632e 100644 --- a/libgo/go/regexp/syntax/doc.go +++ b/libgo/go/regexp/syntax/doc.go @@ -64,8 +64,8 @@ Empty strings: ^ at beginning of text or line (flag m=true) $ at end of text (like \z not \Z) or line (flag m=true) \A at beginning of text - \b at word boundary (\w on one side and \W, \A, or \z on the other) - \B not a word boundary + \b at ASCII word boundary (\w on one side and \W, \A, or \z on the other) + \B not an ASCII word boundary \z at end of text Escape sequences: @@ -104,8 +104,8 @@ Perl character classes: \D not digits (== [^0-9]) \s whitespace (== [\t\n\f\r ]) \S not whitespace (== [^\t\n\f\r ]) - \w word characters (== [0-9A-Za-z_]) - \W not word characters (== [^0-9A-Za-z_]) + \w ASCII word characters (== [0-9A-Za-z_]) + \W not ASCII word characters (== [^0-9A-Za-z_]) ASCII character classes: [:alnum:] alphanumeric (== [0-9A-Za-z]) diff --git a/libgo/go/regexp/syntax/parse.go b/libgo/go/regexp/syntax/parse.go index 30e0e8b..42d0bf4 100644 --- a/libgo/go/regexp/syntax/parse.go +++ b/libgo/go/regexp/syntax/parse.go @@ -651,7 +651,7 @@ func literalRegexp(s string, flags Flags) *Regexp { // Parse parses a regular expression string s, controlled by the specified // Flags, and returns a regular expression parse tree. The syntax is -// described in the top-level comment for package regexp. +// described in the top-level comment. func Parse(s string, flags Flags) (*Regexp, error) { if flags&Literal != 0 { // Trivial parser for literal string. diff --git a/libgo/go/regexp/syntax/parse_test.go b/libgo/go/regexp/syntax/parse_test.go index 81fd9dc..269d6c3 100644 --- a/libgo/go/regexp/syntax/parse_test.go +++ b/libgo/go/regexp/syntax/parse_test.go @@ -542,7 +542,7 @@ func TestToStringEquivalentParse(t *testing.T) { // but "{" is a shorter equivalent in some contexts. nre, err := Parse(s, testFlags) if err != nil { - t.Errorf("Parse(%#q.String() = %#q): %v", tt.Regexp, t, err) + t.Errorf("Parse(%#q.String() = %#q): %v", tt.Regexp, s, err) continue } nd := dump(nre) diff --git a/libgo/go/regexp/syntax/prog.go b/libgo/go/regexp/syntax/prog.go index 902d3b3..a482a82 100644 --- a/libgo/go/regexp/syntax/prog.go +++ b/libgo/go/regexp/syntax/prog.go @@ -56,23 +56,26 @@ const ( // Passing r2 == -1 indicates that the position is // at the end of the text. func EmptyOpContext(r1, r2 rune) EmptyOp { - var op EmptyOp - if r1 < 0 { - op |= EmptyBeginText | EmptyBeginLine - } - if r1 == '\n' { + var op EmptyOp = EmptyNoWordBoundary + var boundary byte + switch { + case IsWordChar(r1): + boundary = 1 + case r1 == '\n': op |= EmptyBeginLine + case r1 < 0: + op |= EmptyBeginText | EmptyBeginLine } - if r2 < 0 { - op |= EmptyEndText | EmptyEndLine - } - if r2 == '\n' { + switch { + case IsWordChar(r2): + boundary ^= 1 + case r2 == '\n': op |= EmptyEndLine + case r2 < 0: + op |= EmptyEndText | EmptyEndLine } - if IsWordChar(r1) != IsWordChar(r2) { - op |= EmptyWordBoundary - } else { - op |= EmptyNoWordBoundary + if boundary != 0 { // IsWordChar(r1) != IsWordChar(r2) + op ^= (EmptyWordBoundary | EmptyNoWordBoundary) } return op } diff --git a/libgo/go/regexp/syntax/prog_test.go b/libgo/go/regexp/syntax/prog_test.go index 663d5a8..cd71abc2 100644 --- a/libgo/go/regexp/syntax/prog_test.go +++ b/libgo/go/regexp/syntax/prog_test.go @@ -103,3 +103,14 @@ func TestCompile(t *testing.T) { } } } + +func BenchmarkEmptyOpContext(b *testing.B) { + for i := 0; i < b.N; i++ { + var r1 rune = -1 + for _, r2 := range "foo, bar, baz\nsome input text.\n" { + EmptyOpContext(r1, r2) + r1 = r2 + } + EmptyOpContext(r1, -1) + } +} |