From eda71f304e61e6e6bdd23c0a434d44efba4f7a98 Mon Sep 17 00:00:00 2001 From: Maurice Makaay Date: Sat, 27 Jul 2019 12:26:02 +0000 Subject: [PATCH] Dropped PeekWithResult(), because it does not add any substantial performance. A simpler API which is virtually as fast wins any day. --- parse/api.go | 27 +++++---------------------- 1 file changed, 5 insertions(+), 22 deletions(-) diff --git a/parse/api.go b/parse/api.go index 67fcd72..ab1928a 100644 --- a/parse/api.go +++ b/parse/api.go @@ -22,40 +22,23 @@ type API struct { 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. // 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. // // 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 { tokenAPI := parseAPI.tokenAPI snap := tokenAPI.MakeSnapshot() parseAPI.Result.Tokens = nil parseAPI.Result.Bytes = nil ok := parseAPI.invokeTokenizeHandler("Peek", tokenHandler) + if ok { + parseAPI.Result.Tokens = tokenAPI.Output.Tokens() + parseAPI.Result.Bytes = tokenAPI.Output.Bytes() + } tokenAPI.RestoreSnapshot(snap) return ok }