Skip to content

Commit 0260c89

Browse files
committed
fix #286 calcHash should use byte not rune to calc hash
1 parent 10a568c commit 0260c89

File tree

2 files changed

+9
-7
lines changed

2 files changed

+9
-7
lines changed

iter_object.go

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ package jsoniter
22

33
import (
44
"fmt"
5-
"unicode"
5+
"strings"
66
)
77

88
// ReadObject read one field from object.
@@ -96,13 +96,12 @@ func (iter *Iterator) readFieldHash() int64 {
9696
}
9797

9898
func calcHash(str string, caseSensitive bool) int64 {
99+
if !caseSensitive {
100+
str = strings.ToLower(str)
101+
}
99102
hash := int64(0x811c9dc5)
100-
for _, b := range str {
101-
if caseSensitive {
102-
hash ^= int64(b)
103-
} else {
104-
hash ^= int64(unicode.ToLower(b))
105-
}
103+
for _, b := range []byte(str) {
104+
hash ^= int64(b)
106105
hash *= 0x1000193
107106
}
108107
return int64(hash)

type_tests/struct_tags_test.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -145,6 +145,9 @@ func init() {
145145
(*struct {
146146
Field bool `json:",omitempty,string"`
147147
})(nil),
148+
(*struct {
149+
Field bool `json:"中文"`
150+
})(nil),
148151
)
149152
}
150153

0 commit comments

Comments
 (0)