aboutsummaryrefslogtreecommitdiff
path: root/src/encoding/json/jsontext
diff options
context:
space:
mode:
Diffstat (limited to 'src/encoding/json/jsontext')
-rw-r--r--src/encoding/json/jsontext/decode_test.go4
-rw-r--r--src/encoding/json/jsontext/token.go31
2 files changed, 28 insertions, 7 deletions
diff --git a/src/encoding/json/jsontext/decode_test.go b/src/encoding/json/jsontext/decode_test.go
index 209ff65ec8..3f48cae2d1 100644
--- a/src/encoding/json/jsontext/decode_test.go
+++ b/src/encoding/json/jsontext/decode_test.go
@@ -193,8 +193,8 @@ var decoderErrorTestdata = []struct {
name: jsontest.Name("InvalidStart"),
in: ` #`,
calls: []decoderMethodCall{
- {'#', zeroToken, newInvalidCharacterError("#", "at start of value").withPos(" ", ""), ""},
- {'#', zeroValue, newInvalidCharacterError("#", "at start of value").withPos(" ", ""), ""},
+ {0, zeroToken, newInvalidCharacterError("#", "at start of value").withPos(" ", ""), ""},
+ {0, zeroValue, newInvalidCharacterError("#", "at start of value").withPos(" ", ""), ""},
},
}, {
name: jsontest.Name("StreamN0"),
diff --git a/src/encoding/json/jsontext/token.go b/src/encoding/json/jsontext/token.go
index e78c3f84d8..caf0174923 100644
--- a/src/encoding/json/jsontext/token.go
+++ b/src/encoding/json/jsontext/token.go
@@ -518,10 +518,31 @@ func (k Kind) String() string {
}
}
-// normalize coalesces all possible starting characters of a number as just '0'.
+var normKind = [256]Kind{
+ 'n': 'n',
+ 'f': 'f',
+ 't': 't',
+ '"': '"',
+ '{': '{',
+ '}': '}',
+ '[': '[',
+ ']': ']',
+ '-': '0',
+ '0': '0',
+ '1': '0',
+ '2': '0',
+ '3': '0',
+ '4': '0',
+ '5': '0',
+ '6': '0',
+ '7': '0',
+ '8': '0',
+ '9': '0',
+}
+
+// normalize coalesces all possible starting characters of a number as just '0',
+// and converts all invalid kinds to 0.
func (k Kind) normalize() Kind {
- if k == '-' || ('0' <= k && k <= '9') {
- return '0'
- }
- return k
+ // A lookup table keeps the inlining cost as low as possible.
+ return normKind[k]
}