Skip to content

Commit

Permalink
start using new strconv package in json parser
Browse files Browse the repository at this point in the history
  • Loading branch information
awalterschulze committed Jan 29, 2025
1 parent 9c50157 commit d127e99
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 10 deletions.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ bench:
memprofile:
rm mem.out || true
rm profile*.* || true
go test -test.v -test.run=XXX -test.bench=. -test.memprofile=mem.out ./...
go test -test.v -test.run=XXX -test.bench=. -test.memprofile=mem.out ./json
go tool pprof -alloc_space -png mem.out

gofmt:
Expand Down
13 changes: 5 additions & 8 deletions json/json.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ package json
import (
"bytes"
"io"
"strconv"

"github.com/katydid/parser-go-json/json/strconv"
"github.com/katydid/parser-go/parser"
)

Expand Down Expand Up @@ -498,19 +498,17 @@ func (s *jsonParser) value() []byte {

func (s *jsonParser) Double() (float64, error) {
if s.isLeaf {
v := string(s.buf)
i, err := strconv.ParseFloat(v, 64)
i, err := strconv.ParseFloat(s.buf)
return i, err
}
return 0, parser.ErrNotDouble
}

func (s *jsonParser) Int() (int64, error) {
if s.isLeaf {
v := string(s.buf)
i, err := strconv.ParseInt(v, 10, 64)
i, err := strconv.ParseInt(s.buf)
if err != nil {
f, ferr := strconv.ParseFloat(v, 64)
f, ferr := strconv.ParseFloat(s.buf)
if ferr != nil {
return i, err
}
Expand All @@ -528,8 +526,7 @@ func (s *jsonParser) Int() (int64, error) {

func (s *jsonParser) Uint() (uint64, error) {
if s.isLeaf {
v := string(s.buf)
i, err := strconv.ParseUint(v, 10, 64)
i, err := strconv.ParseUint(s.buf)
return uint64(i), err
}
return 0, parser.ErrNotUint
Expand Down
1 change: 0 additions & 1 deletion json/strconv/atoi_errors.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,6 @@ var errSyntaxParseInt = &NumError{"ParseInt", ErrSyntax}
var errSyntaxParseUint = &NumError{"ParseUint", ErrSyntax}
var errSyntaxParseFloat = &NumError{"ParseFloat", ErrSyntax}

var errRangeAtoi = &NumError{"Atoi", ErrRange}
var errRangeParseInt = &NumError{"ParseInt", ErrRange}
var errRangeParseUint = &NumError{"ParseUint", ErrRange}
var errRangeParseFloat = &NumError{"ParseFloat", ErrRange}

0 comments on commit d127e99

Please sign in to comment.