Dropped PeekWithResult(), because it does not add any substantial performance. A simpler API which is virtually as fast wins any day.
This commit is contained in:
parent
fcdd3d4ea7
commit
eda71f304e
27
parse/api.go
27
parse/api.go
|
@ -22,40 +22,23 @@ type API struct {
|
||||||
stopped bool // a boolean set to true by Stop()
|
stopped bool // a boolean set to true by Stop()
|
||||||
}
|
}
|
||||||
|
|
||||||
// PeekWithResult checks if the upcoming input data matches the provided tokenize.Handler.
|
|
||||||
// If it does, then true will be returned, false otherwise. The read cursor
|
|
||||||
// will be kept at the same position, so the next call to Peek() or Accept()
|
|
||||||
// will start from the same cursor position.
|
|
||||||
//
|
|
||||||
// On a successful peek, the results (data + tokens) are returned by the peek.
|
|
||||||
// They are availablel (as with Accept()) through parse.API.Result.
|
|
||||||
func (parseAPI *API) PeekWithResult(tokenHandler tokenize.Handler) bool {
|
|
||||||
tokenAPI := parseAPI.tokenAPI
|
|
||||||
snap := tokenAPI.MakeSnapshot()
|
|
||||||
parseAPI.Result.Tokens = nil
|
|
||||||
parseAPI.Result.Bytes = nil
|
|
||||||
ok := parseAPI.invokeTokenizeHandler("PeekWithResult", tokenHandler)
|
|
||||||
if ok {
|
|
||||||
parseAPI.Result.Tokens = tokenAPI.Output.Tokens()
|
|
||||||
parseAPI.Result.Bytes = tokenAPI.Output.Bytes()
|
|
||||||
}
|
|
||||||
tokenAPI.RestoreSnapshot(snap)
|
|
||||||
return ok
|
|
||||||
}
|
|
||||||
|
|
||||||
// Peek checks if the upcoming input data matches the provided tokenize.Handler.
|
// Peek checks if the upcoming input data matches the provided tokenize.Handler.
|
||||||
// If it does, then true will be returned, false otherwise. The read cursor
|
// If it does, then true will be returned, false otherwise. The read cursor
|
||||||
// will be kept at the same position, so the next call to Peek() or Accept()
|
// will be kept at the same position, so the next call to Peek() or Accept()
|
||||||
// will start from the same cursor position.
|
// will start from the same cursor position.
|
||||||
//
|
//
|
||||||
// No results (data + tokens) are returned by Peek(). If want access to the data
|
// No results (data + tokens) are returned by Peek(). If want access to the data
|
||||||
// through parse.API.Result, make use of PeekWithResult() instead.
|
// through parse.API.Result, make use of Peek() instead.
|
||||||
func (parseAPI *API) Peek(tokenHandler tokenize.Handler) bool {
|
func (parseAPI *API) Peek(tokenHandler tokenize.Handler) bool {
|
||||||
tokenAPI := parseAPI.tokenAPI
|
tokenAPI := parseAPI.tokenAPI
|
||||||
snap := tokenAPI.MakeSnapshot()
|
snap := tokenAPI.MakeSnapshot()
|
||||||
parseAPI.Result.Tokens = nil
|
parseAPI.Result.Tokens = nil
|
||||||
parseAPI.Result.Bytes = nil
|
parseAPI.Result.Bytes = nil
|
||||||
ok := parseAPI.invokeTokenizeHandler("Peek", tokenHandler)
|
ok := parseAPI.invokeTokenizeHandler("Peek", tokenHandler)
|
||||||
|
if ok {
|
||||||
|
parseAPI.Result.Tokens = tokenAPI.Output.Tokens()
|
||||||
|
parseAPI.Result.Bytes = tokenAPI.Output.Bytes()
|
||||||
|
}
|
||||||
tokenAPI.RestoreSnapshot(snap)
|
tokenAPI.RestoreSnapshot(snap)
|
||||||
return ok
|
return ok
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue