diff options
author | Rob Pike <r@golang.org> | 2009-11-02 11:37:52 -0800 |
---|---|---|
committer | Rob Pike <r@golang.org> | 2009-11-02 11:37:52 -0800 |
commit | 011ab3e966dd1b4fb4676bae60be8aa713321d39 (patch) | |
tree | 3be73d8cfb41421f6a82744ae483cbd6b11ad28c /test/bench/regex-dna.go | |
parent | 8b0d256638ba1ca1aa6325c036bb2df1609ea006 (diff) | |
download | golang-011ab3e966dd1b4fb4676bae60be8aa713321d39.tar.gz |
use the new routine regexp.MustCompile to clean up some code that uses global regexps.
R=rsc, gri
CC=go-dev
http://go/go-review/1016025
Diffstat (limited to 'test/bench/regex-dna.go')
-rw-r--r-- | test/bench/regex-dna.go | 15 |
1 files changed, 3 insertions, 12 deletions
diff --git a/test/bench/regex-dna.go b/test/bench/regex-dna.go index f42efc6d4..f04422c3f 100644 --- a/test/bench/regex-dna.go +++ b/test/bench/regex-dna.go @@ -43,15 +43,6 @@ import ( "strings"; ) -func compile(s string) *regexp.Regexp { - r, err := regexp.Compile(s); - if err != nil { - fmt.Fprintf(os.Stderr, "can't compile pattern %q: %s\n", s, err); - os.Exit(2); - } - return r; -} - var variants = []string { "agggtaaa|tttaccct", "[cgt]gggtaaa|tttaccc[acg]", @@ -83,7 +74,7 @@ var substs = [] Subst { } func countMatches(pat string, bytes []byte) int { - re := compile(pat); + re := regexp.MustCompile(pat); n := 0; for { e := re.Execute(bytes); @@ -104,13 +95,13 @@ func main() { } ilen := len(bytes); // Delete the comment lines and newlines - bytes = compile("(>[^\n]+)?\n").ReplaceAll(bytes, []byte{}); + bytes = regexp.MustCompile("(>[^\n]+)?\n").ReplaceAll(bytes, []byte{}); clen := len(bytes); for _, s := range variants { fmt.Printf("%s %d\n", s, countMatches(s, bytes)); } for _, sub := range substs { - bytes = compile(sub.pat).ReplaceAll(bytes, strings.Bytes(sub.repl)); + bytes = regexp.MustCompile(sub.pat).ReplaceAll(bytes, strings.Bytes(sub.repl)); } fmt.Printf("\n%d\n%d\n%d\n", ilen, clen, len(bytes)); } |