Skip to content

Commit

Permalink
perf: Remove unnecessary goto
Browse files Browse the repository at this point in the history
  • Loading branch information
romshark committed Dec 30, 2023
1 parent 8ab9ae2 commit acfc892
Showing 1 changed file with 31 additions and 33 deletions.
64 changes: 31 additions & 33 deletions internal/jsonnum/jsonnum.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ func ReadNumber[S ~string | ~[]byte](s S) (trailing S, err bool) {
s = s[1:]
if len(s) < 1 {
// Zero
goto RETURN
return s, false
}
// Leading zero
switch s[0] {
Expand All @@ -30,7 +30,7 @@ func ReadNumber[S ~string | ~[]byte](s S) (trailing S, err bool) {
goto EXPONENT_SIGN
default:
// Zero
goto RETURN
return s, false
}
}

Expand All @@ -50,7 +50,7 @@ func ReadNumber[S ~string | ~[]byte](s S) (trailing S, err bool) {
goto FRACTION
}
// Integer
goto RETURN
return s, false
}
if s[1] < '0' || s[1] > '9' {
if s[1] == 'e' || s[1] == 'E' {
Expand All @@ -62,7 +62,7 @@ func ReadNumber[S ~string | ~[]byte](s S) (trailing S, err bool) {
}
// Integer
s = s[1:]
goto RETURN
return s, false
}
if s[2] < '0' || s[2] > '9' {
if s[2] == 'e' || s[2] == 'E' {
Expand All @@ -74,7 +74,7 @@ func ReadNumber[S ~string | ~[]byte](s S) (trailing S, err bool) {
}
// Integer
s = s[2:]
goto RETURN
return s, false
}
if s[3] < '0' || s[3] > '9' {
if s[3] == 'e' || s[3] == 'E' {
Expand All @@ -86,7 +86,7 @@ func ReadNumber[S ~string | ~[]byte](s S) (trailing S, err bool) {
}
// Integer
s = s[3:]
goto RETURN
return s, false
}
if s[4] < '0' || s[4] > '9' {
if s[4] == 'e' || s[4] == 'E' {
Expand All @@ -98,7 +98,7 @@ func ReadNumber[S ~string | ~[]byte](s S) (trailing S, err bool) {
}
// Integer
s = s[4:]
goto RETURN
return s, false
}
if s[5] < '0' || s[5] > '9' {
if s[5] == 'e' || s[5] == 'E' {
Expand All @@ -110,7 +110,7 @@ func ReadNumber[S ~string | ~[]byte](s S) (trailing S, err bool) {
}
// Integer
s = s[5:]
goto RETURN
return s, false
}
if s[6] < '0' || s[6] > '9' {
if s[6] == 'e' || s[6] == 'E' {
Expand All @@ -122,7 +122,7 @@ func ReadNumber[S ~string | ~[]byte](s S) (trailing S, err bool) {
}
// Integer
s = s[6:]
goto RETURN
return s, false
}
if s[7] < '0' || s[7] > '9' {
if s[7] == 'e' || s[7] == 'E' {
Expand All @@ -134,7 +134,7 @@ func ReadNumber[S ~string | ~[]byte](s S) (trailing S, err bool) {
}
// Integer
s = s[7:]
goto RETURN
return s, false
}
s = s[8:]
}
Expand All @@ -149,14 +149,14 @@ func ReadNumber[S ~string | ~[]byte](s S) (trailing S, err bool) {
}
// Integer
s = s[i:]
goto RETURN
return s, false
}
}
s = s[i:]

if len(s) < 1 {
// Integer without exponent
goto RETURN
return s, false
}

FRACTION:
Expand All @@ -172,63 +172,63 @@ FRACTION:
s = s[1:]
goto EXPONENT_SIGN
}
goto RETURN
return s, false
}
if s[1] < '0' || s[1] > '9' {
if s[1] == 'e' || s[1] == 'E' {
s = s[2:]
goto EXPONENT_SIGN
}
s = s[1:]
goto RETURN
return s, false
}
if s[2] < '0' || s[2] > '9' {
if s[2] == 'e' || s[2] == 'E' {
s = s[3:]
goto EXPONENT_SIGN
}
s = s[2:]
goto RETURN
return s, false
}
if s[3] < '0' || s[3] > '9' {
if s[3] == 'e' || s[3] == 'E' {
s = s[4:]
goto EXPONENT_SIGN
}
s = s[3:]
goto RETURN
return s, false
}
if s[4] < '0' || s[4] > '9' {
if s[4] == 'e' || s[4] == 'E' {
s = s[5:]
goto EXPONENT_SIGN
}
s = s[4:]
goto RETURN
return s, false
}
if s[5] < '0' || s[5] > '9' {
if s[5] == 'e' || s[5] == 'E' {
s = s[6:]
goto EXPONENT_SIGN
}
s = s[5:]
goto RETURN
return s, false
}
if s[6] < '0' || s[6] > '9' {
if s[6] == 'e' || s[6] == 'E' {
s = s[7:]
goto EXPONENT_SIGN
}
s = s[6:]
goto RETURN
return s, false
}
if s[7] < '0' || s[7] > '9' {
if s[7] == 'e' || s[7] == 'E' {
s = s[8:]
goto EXPONENT_SIGN
}
s = s[7:]
goto RETURN
return s, false
}
s = s[8:]
}
Expand All @@ -239,14 +239,14 @@ FRACTION:
goto EXPONENT_SIGN
}
s = s[i:]
goto RETURN
return s, false
}
}
s = s[i:]

if len(s) < 1 {
// Number (with fraction but) without exponent
goto RETURN
return s, false
}

EXPONENT_SIGN:
Expand All @@ -266,54 +266,52 @@ EXPONENT_SIGN:
for len(s) >= 8 {
if s[0] < '0' || s[0] > '9' {
// Number with (fraction and) exponent
goto RETURN
return s, false
}
if s[1] < '0' || s[1] > '9' {
// Number with (fraction and) exponent
s = s[1:]
goto RETURN
return s, false
}
if s[2] < '0' || s[2] > '9' {
// Number with (fraction and) exponent
s = s[2:]
goto RETURN
return s, false
}
if s[3] < '0' || s[3] > '9' {
// Number with (fraction and) exponent
s = s[3:]
goto RETURN
return s, false
}
if s[4] < '0' || s[4] > '9' {
// Number with (fraction and) exponent
s = s[4:]
goto RETURN
return s, false
}
if s[5] < '0' || s[5] > '9' {
// Number with (fraction and) exponent
s = s[5:]
goto RETURN
return s, false
}
if s[6] < '0' || s[6] > '9' {
// Number with (fraction and) exponent
s = s[6:]
goto RETURN
return s, false
}
if s[7] < '0' || s[7] > '9' {
// Number with (fraction and) exponent
s = s[7:]
goto RETURN
return s, false
}
s = s[8:]
}
for i = 0; i < len(s); i++ {
if s[i] < '0' || s[i] > '9' {
// Number with (fraction and) exponent
s = s[i:]
goto RETURN
return s, false
}
}
s = s[i:]

RETURN:
return s, false
}

0 comments on commit acfc892

Please sign in to comment.