Skip to content

Commit

Permalink
regexp: hide one-pass code from exported API
Browse files Browse the repository at this point in the history
Update golang#8112

Hide one-pass regexp API.

This means moving the code from regexp/syntax to regexp,
but it avoids being locked into the specific API chosen for
the implementation.

It also removes a slice field from the syntax.Inst, which
should avoid bloating the memory footprint of a non-one-pass
regexp unnecessarily.

LGTM=r
R=golang-codereviews, r
CC=golang-codereviews, iant
https://golang.org/cl/98610046
  • Loading branch information
rsc committed May 28, 2014
1 parent 0782ee3 commit 6c10e64
Show file tree
Hide file tree
Showing 7 changed files with 804 additions and 756 deletions.
5 changes: 0 additions & 5 deletions api/next.txt
Original file line number Diff line number Diff line change
Expand Up @@ -330,12 +330,7 @@ pkg net/http, type Server struct, ConnState func(net.Conn, ConnState)
pkg net/http, type Server struct, ErrorLog *log.Logger
pkg net/http, type Transport struct, TLSHandshakeTimeout time.Duration
pkg regexp/syntax, method (*Inst) MatchRunePos(int32) int
pkg regexp/syntax, method (*Inst) OnePassNext(int32) uint32
pkg regexp/syntax, method (*Prog) CompileOnePass() *Prog
pkg regexp/syntax, method (*Prog) OnePassPrefix() (string, bool, uint32)
pkg regexp/syntax, method (InstOp) String() string
pkg regexp/syntax, type Inst struct, Next []uint32
pkg regexp/syntax, var NotOnePass *Prog
pkg runtime/debug, func SetPanicOnFault(bool) bool
pkg runtime/debug, func WriteHeapDump(uintptr)
pkg sync, method (*Pool) Get() interface{}
Expand Down
8 changes: 4 additions & 4 deletions src/pkg/regexp/exec.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ type thread struct {
type machine struct {
re *Regexp // corresponding Regexp
p *syntax.Prog // compiled program
op *syntax.Prog // compiled onepass program, or syntax.NotOnePass
op *onePassProg // compiled onepass program, or notOnePass
q0, q1 queue // two queues for runq, nextq
pool []*thread // pool of available threads
matched bool // whether a match was found
Expand Down Expand Up @@ -67,7 +67,7 @@ func (m *machine) newInputReader(r io.RuneReader) input {
}

// progMachine returns a new machine running the prog p.
func progMachine(p, op *syntax.Prog) *machine {
func progMachine(p *syntax.Prog, op *onePassProg) *machine {
m := &machine{p: p, op: op}
n := len(m.p.Inst)
m.q0 = queue{make([]uint32, n), make([]entry, 0, n)}
Expand Down Expand Up @@ -382,7 +382,7 @@ func (m *machine) onepass(i input, pos int) bool {
}
// peek at the input rune to see which branch of the Alt to take
case syntax.InstAlt, syntax.InstAltMatch:
pc = int(inst.OnePassNext(r))
pc = int(onePassNext(&inst, r))
continue
case syntax.InstFail:
return m.matched
Expand Down Expand Up @@ -429,7 +429,7 @@ func (re *Regexp) doExecute(r io.RuneReader, b []byte, s string, pos int, ncap i
} else {
i = m.newInputString(s)
}
if m.op != syntax.NotOnePass {
if m.op != notOnePass {
if !m.onepass(i, pos) {
re.put(m)
return nil
Expand Down
Loading

0 comments on commit 6c10e64

Please sign in to comment.