allocate only once in generated code
This commit is contained in:
parent
9f1a457c24
commit
b589e4d0df
@ -899,7 +899,7 @@ func parseInput(r io.Reader, p parser, b builder, kw []parser, maxTraceLength in
|
||||
|
||||
// eo head
|
||||
|
||||
func Parse(r io.Reader) (Node, error) {
|
||||
var selfParse = func() func(io.Reader) (Node, error) {
|
||||
|
||||
var p183 = sequenceParser{id: 183, commit: 768, name: "syntax", ranges: [][]int{{0, -1}, {1, 1}, {0, -1}}}
|
||||
var p181 = choiceParser{id: 181, commit: 2}
|
||||
@ -1469,6 +1469,11 @@ func Parse(r io.Reader) (Node, error) {
|
||||
b183.items = []builder{&b181, &b182, &b181}
|
||||
|
||||
var keywords = []parser{}
|
||||
|
||||
return func(r io.Reader) (Node, error) {
|
||||
return parseInput(r, &p183, &b183, keywords, 0)
|
||||
}
|
||||
}()
|
||||
|
||||
func Parse(r io.Reader) (Node, error) {
|
||||
return selfParse(r)
|
||||
}
|
||||
|
||||
21
syntax.go
21
syntax.go
@ -539,12 +539,7 @@ func (s *Syntax) Generate(o GeneratorOptions, w io.Writer) error {
|
||||
fprintln()
|
||||
fprintln()
|
||||
|
||||
if o.Export {
|
||||
fprint(`func Parse(r io.Reader) (Node, error) {`)
|
||||
} else {
|
||||
fprint(`func parse(r io.Reader) (node, error) {`)
|
||||
}
|
||||
|
||||
fprintf(`var %sParse = func() func(io.Reader) (Node, error) {`, o.PackageName)
|
||||
fprintln()
|
||||
|
||||
done := make(map[string]bool)
|
||||
@ -573,8 +568,22 @@ func (s *Syntax) Generate(o GeneratorOptions, w io.Writer) error {
|
||||
fprint(`}`)
|
||||
|
||||
fprintln()
|
||||
fprint(`return func(r io.Reader) (Node, error) {`)
|
||||
fprintln()
|
||||
fprintf(`return parseInput(r, &p%d, &b%d, keywords, 0)`, s.root.parser().nodeID(), s.root.builder().nodeID())
|
||||
fprint(`}`)
|
||||
fprintln()
|
||||
fprint(`}()`)
|
||||
fprintln()
|
||||
|
||||
if o.Export {
|
||||
fprint(`func Parse(r io.Reader) (Node, error) {`)
|
||||
} else {
|
||||
fprint(`func parse(r io.Reader) (node, error) {`)
|
||||
}
|
||||
|
||||
fprintln()
|
||||
fprintf(`return %sParse(r)`, o.PackageName)
|
||||
fprintln()
|
||||
fprint(`}`)
|
||||
fprintln()
|
||||
|
||||
Loading…
Reference in New Issue
Block a user