From acfc892c62ff591bb7ca5566aac92497f0d6c71f Mon Sep 17 00:00:00 2001 From: Roman Sharkov Date: Sat, 30 Dec 2023 15:35:37 +0100 Subject: [PATCH] perf: Remove unnecessary goto --- internal/jsonnum/jsonnum.go | 64 ++++++++++++++++++------------------- 1 file changed, 31 insertions(+), 33 deletions(-) diff --git a/internal/jsonnum/jsonnum.go b/internal/jsonnum/jsonnum.go index 6b845aa..d170d36 100644 --- a/internal/jsonnum/jsonnum.go +++ b/internal/jsonnum/jsonnum.go @@ -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] { @@ -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 } } @@ -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' { @@ -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' { @@ -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' { @@ -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' { @@ -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' { @@ -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' { @@ -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' { @@ -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:] } @@ -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: @@ -172,7 +172,7 @@ 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' { @@ -180,7 +180,7 @@ FRACTION: 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' { @@ -188,7 +188,7 @@ FRACTION: 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' { @@ -196,7 +196,7 @@ FRACTION: 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' { @@ -204,7 +204,7 @@ FRACTION: 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' { @@ -212,7 +212,7 @@ FRACTION: 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' { @@ -220,7 +220,7 @@ FRACTION: 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' { @@ -228,7 +228,7 @@ FRACTION: goto EXPONENT_SIGN } s = s[7:] - goto RETURN + return s, false } s = s[8:] } @@ -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: @@ -266,42 +266,42 @@ 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:] } @@ -309,11 +309,9 @@ EXPONENT_SIGN: 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 }