Skip to content

Commit

Permalink
feat: inline reading to consume
Browse files Browse the repository at this point in the history
  • Loading branch information
tdakkota committed Jan 13, 2022
1 parent 0762622 commit 1f8d31d
Showing 1 changed file with 15 additions and 4 deletions.
19 changes: 15 additions & 4 deletions dec.go
Original file line number Diff line number Diff line change
Expand Up @@ -165,10 +165,21 @@ func (d *Decoder) Next() Type {
return types[v]
}

func (d *Decoder) consume(c byte) error {
got, err := d.more()
if err != nil {
return err
var spaceSet = [256]byte{
' ': 1, '\n': 1, '\t': 1, '\r': 1,
}

func (d *Decoder) consume(c byte) (err error) {
buf := d.buf[d.head:d.tail]
var got byte
if len(buf) > 0 && spaceSet[buf[0]] == 0 {
d.head++
got = buf[0]
} else {
got, err = d.more()
if err != nil {
return err
}
}
if c != got {
return badToken(got)
Expand Down

0 comments on commit 1f8d31d

Please sign in to comment.