diff options
author | Adam Scarr <adam@vektah.net> | 2017-08-07 21:38:46 +1000 |
---|---|---|
committer | Adam Scarr <adam@vektah.net> | 2017-08-07 21:38:46 +1000 |
commit | 132876fce437c35fc861b0796cd231405250bbd5 (patch) | |
tree | 409078673207a3745606a83a32407faa8ad0dd06 /state.go | |
parent | a656dc0d78c5f51a16dc4c26936d337cdae5105c (diff) |
Small perf tweaks
Diffstat (limited to 'state.go')
-rw-r--r-- | state.go | 18 |
1 files changed, 10 insertions, 8 deletions
@@ -2,8 +2,6 @@ package goparsify import ( "fmt" - "strings" - "unicode/utf8" ) type Error struct { @@ -18,7 +16,7 @@ type State struct { Input string Pos int Error Error - WSChars string + WSChars []byte NoAutoWS bool } @@ -35,13 +33,17 @@ func (s *State) AutoWS() { } func (s *State) WS() { +loop: for s.Pos < len(s.Input) { - r, w := utf8.DecodeRuneInString(s.Input[s.Pos:]) - if !strings.ContainsRune(s.WSChars, r) { - return + // Pretty sure this is unicode safe as long as WSChars is only in the ascii range... + for _, ws := range s.WSChars { + if s.Input[s.Pos] == ws { + s.Pos++ + continue loop + } } - s.Pos += w + return } } @@ -66,5 +68,5 @@ func (s *State) Errored() bool { } func InputString(input string) *State { - return &State{Input: input, WSChars: "\t\n\v\f\r \x85\xA0"} + return &State{Input: input, WSChars: []byte("\t\n\v\f\r ")} } |