Skip to content

Commit

Permalink
opt: eliminate race test errors
Browse files Browse the repository at this point in the history
  • Loading branch information
AsterDY committed Oct 26, 2023
1 parent de254c3 commit d97e4b6
Showing 1 changed file with 20 additions and 20 deletions.
40 changes: 20 additions & 20 deletions ast/decode.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,16 +42,16 @@ func isSpace(c byte) bool {

//go:nocheckptr
func skipBlank(src string, pos int) int {
se := uintptr(rt.IndexChar(src, len(src)))
se := uintptr(rt.IndexChar(src, len(src)-1))
sp := uintptr(rt.IndexChar(src, pos))

for sp < se {
for sp <= se {
if !isSpace(*(*byte)(unsafe.Pointer(sp))) {
break
}
sp += 1
}
if sp >= se {
if sp > se {
return -int(types.ERR_EOF)
}
runtime.KeepAlive(src)
Expand Down Expand Up @@ -134,25 +134,25 @@ func isDigit(c byte) bool {
func decodeInt64(src string, pos int) (ret int, v int64, err error) {
sp := uintptr(rt.IndexChar(src, pos))
ss := uintptr(sp)
se := uintptr(rt.IndexChar(src, len(src)))
if uintptr(sp) >= se {
se := uintptr(rt.IndexChar(src, len(src)-1))
if uintptr(sp) > se {
return -int(types.ERR_EOF), 0, nil
}

if c := *(*byte)(unsafe.Pointer(sp)); c == '-' {
sp += 1
}
if sp == se {
if sp > se {
return -int(types.ERR_EOF), 0, nil
}

for ; sp < se; sp += uintptr(1) {
for ; sp <= se; sp += uintptr(1) {
if !isDigit(*(*byte)(unsafe.Pointer(sp))) {
break
}
}

if sp < se {
if sp <= se {
if c := *(*byte)(unsafe.Pointer(sp)); c == '.' || c == 'e' || c == 'E' {
return -int(types.ERR_INVALID_NUMBER_FMT), 0, nil
}
Expand Down Expand Up @@ -184,19 +184,19 @@ func isNumberChars(c byte) bool {
func decodeFloat64(src string, pos int) (ret int, v float64, err error) {
sp := uintptr(rt.IndexChar(src, pos))
ss := uintptr(sp)
se := uintptr(rt.IndexChar(src, len(src)))
if uintptr(sp) >= se {
se := uintptr(rt.IndexChar(src, len(src)-1))
if uintptr(sp) > se {
return -int(types.ERR_EOF), 0, nil
}

if c := *(*byte)(unsafe.Pointer(sp)); c == '-' {
sp += 1
}
if sp == se {
if sp > se {
return -int(types.ERR_EOF), 0, nil
}

for ; sp < se; sp += uintptr(1) {
for ; sp <= se; sp += uintptr(1) {
if !isNumberChars(*(*byte)(unsafe.Pointer(sp))) {
break
}
Expand Down Expand Up @@ -288,8 +288,8 @@ func decodeValue(src string, pos int, skipnum bool) (ret int, v types.JsonState)
//go:nocheckptr
func skipNumber(src string, pos int) (ret int) {
sp := uintptr(rt.IndexChar(src, pos))
se := uintptr(rt.IndexChar(src, len(src)))
if uintptr(sp) >= se {
se := uintptr(rt.IndexChar(src, len(src)-1))
if uintptr(sp) > se {
return -int(types.ERR_EOF)
}

Expand All @@ -303,7 +303,7 @@ func skipNumber(src string, pos int) (ret int) {
var lastIsDigit bool
var nextNeedDigit = true

for ; sp < se; sp += uintptr(1) {
for ; sp <= se; sp += uintptr(1) {
c := *(*byte)(unsafe.Pointer(sp))
if isDigit(c) {
lastIsDigit = true
Expand All @@ -323,7 +323,7 @@ func skipNumber(src string, pos int) (ret int) {
if !lastIsDigit || exponent {
return -int(types.ERR_INVALID_CHAR)
}
if sp == se-1 {
if sp == se {
return -int(types.ERR_EOF)
}
exponent = true
Expand Down Expand Up @@ -357,7 +357,7 @@ func skipString(src string, pos int) (ret int, ep int) {
}

sp := uintptr(rt.IndexChar(src, pos))
se := uintptr(rt.IndexChar(src, len(src)))
se := uintptr(rt.IndexChar(src, len(src)-1))

// not start with quote
if *(*byte)(unsafe.Pointer(sp)) != '"' {
Expand All @@ -366,7 +366,7 @@ func skipString(src string, pos int) (ret int, ep int) {
sp += 1

ep = -1
for sp < se {
for sp <= se {
c := *(*byte)(unsafe.Pointer(sp))
if c == '\\' {
if ep == -1 {
Expand All @@ -393,7 +393,7 @@ func skipPair(src string, pos int, lchar byte, rchar byte) (ret int) {
}

sp := uintptr(rt.IndexChar(src, pos))
se := uintptr(rt.IndexChar(src, len(src)))
se := uintptr(rt.IndexChar(src, len(src)-1))

if *(*byte)(unsafe.Pointer(sp)) != lchar {
return -int(types.ERR_INVALID_CHAR)
Expand All @@ -403,7 +403,7 @@ func skipPair(src string, pos int, lchar byte, rchar byte) (ret int) {
nbrace := 1
inquote := false

for sp < se {
for sp <= se {
c := *(*byte)(unsafe.Pointer(sp))
if c == '\\' {
sp += 2
Expand Down

0 comments on commit d97e4b6

Please sign in to comment.