diff options
author | Ian Lance Taylor <ian@gcc.gnu.org> | 2012-01-12 01:31:45 +0000 |
---|---|---|
committer | Ian Lance Taylor <ian@gcc.gnu.org> | 2012-01-12 01:31:45 +0000 |
commit | 9a0e3259f44ad2de9c65f14f756dab01b3598391 (patch) | |
tree | 86a3b8019380d5fad53258c4baba3dd9e1e7c736 /libgo/go/regexp/exec.go | |
parent | c6135f063335419e4b5df0b4e1caf145882c8a4b (diff) | |
download | gcc-9a0e3259f44ad2de9c65f14f756dab01b3598391.zip gcc-9a0e3259f44ad2de9c65f14f756dab01b3598391.tar.gz gcc-9a0e3259f44ad2de9c65f14f756dab01b3598391.tar.bz2 |
libgo: Update to weekly.2011-12-14.
From-SVN: r183118
Diffstat (limited to 'libgo/go/regexp/exec.go')
-rw-r--r-- | libgo/go/regexp/exec.go | 40 |
1 files changed, 38 insertions, 2 deletions
diff --git a/libgo/go/regexp/exec.go b/libgo/go/regexp/exec.go index d7057a1..e16a1b5 100644 --- a/libgo/go/regexp/exec.go +++ b/libgo/go/regexp/exec.go @@ -1,6 +1,9 @@ package regexp -import "regexp/syntax" +import ( + "io" + "regexp/syntax" +) // A queue is a 'sparse array' holding pending threads of execution. // See http://research.swtch.com/2008/03/using-uninitialized-memory-for-fun-and.html @@ -34,6 +37,28 @@ type machine struct { pool []*thread // pool of available threads matched bool // whether a match was found matchcap []int // capture information for the match + + // cached inputs, to avoid allocation + inputBytes inputBytes + inputString inputString + inputReader inputReader +} + +func (m *machine) newInputBytes(b []byte) input { + m.inputBytes.str = b + return &m.inputBytes +} + +func (m *machine) newInputString(s string) input { + m.inputString.str = s + return &m.inputString +} + +func (m *machine) newInputReader(r io.RuneReader) input { + m.inputReader.r = r + m.inputReader.atEOT = false + m.inputReader.pos = 0 + return &m.inputReader } // progMachine returns a new machine running the prog p. @@ -74,6 +99,9 @@ func (m *machine) alloc(i *syntax.Inst) *thread { // free returns t to the free pool. func (m *machine) free(t *thread) { + m.inputBytes.str = nil + m.inputString.str = "" + m.inputReader.r = nil m.pool = append(m.pool, t) } @@ -287,8 +315,16 @@ var empty = make([]int, 0) // doExecute finds the leftmost match in the input and returns // the position of its subexpressions. -func (re *Regexp) doExecute(i input, pos int, ncap int) []int { +func (re *Regexp) doExecute(r io.RuneReader, b []byte, s string, pos int, ncap int) []int { m := re.get() + var i input + if r != nil { + i = m.newInputReader(r) + } else if b != nil { + i = m.newInputBytes(b) + } else { + i = m.newInputString(s) + } m.init(ncap) if !m.match(i, pos) { re.put(m) |