Skip to content

Commit

Permalink
Merge pull request #40 from tdakkota/feat/use-number-set
Browse files Browse the repository at this point in the history
feat: use number set to speed up number parsing
  • Loading branch information
tdakkota committed Mar 17, 2022
2 parents fabd6f1 + 75b85e8 commit e09ad96
Showing 1 changed file with 19 additions and 4 deletions.
23 changes: 19 additions & 4 deletions dec_float.go
Expand Up @@ -161,14 +161,29 @@ NonDecimalLoop:
return d.f32Slow()
}

var numberSet = [256]byte{
'+': 1,
'-': 1,
'.': 1,
'e': 1,
'E': 1,
'0': 1,
'1': 1,
'2': 1,
'3': 1,
'4': 1,
'5': 1,
'6': 1,
'7': 1,
'8': 1,
'9': 1,
}

func (d *Decoder) number() []byte {
start := d.head
buf := d.buf[d.head:d.tail]
for i, c := range buf {
switch c {
case '+', '-', '.', 'e', 'E', '0', '1', '2', '3', '4', '5', '6', '7', '8', '9':
continue
default:
if numberSet[c] == 0 {
// End of number.
d.head += i
return d.buf[start:d.head]
Expand Down

0 comments on commit e09ad96

Please sign in to comment.