Skip to content

Commit

Permalink
fix error
Browse files Browse the repository at this point in the history
  • Loading branch information
zerosnake0 committed Mar 22, 2021
1 parent e7412dd commit b7b9995
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 5 deletions.
8 changes: 4 additions & 4 deletions iterator_str.go
Original file line number Diff line number Diff line change
Expand Up @@ -128,8 +128,7 @@ Retry:
}

// internal, call only after a '"' is consumed
// the result is either a part of the original data
// or a part of the temp buffer, should be copied if
// the result is a part of the temp buffer, should be copied if
// the data needs to be saved
func (it *Iterator) readStringAsSlice() (_ []byte, err error) {
for i := it.head; i < it.tail; i++ {
Expand All @@ -138,9 +137,9 @@ func (it *Iterator) readStringAsSlice() (_ []byte, err error) {
return nil, InvalidStringCharError{c: c}
}
if c == '"' {
buf := it.buffer[it.head:i]
it.tmpBuffer = append(it.tmpBuffer[:0], it.buffer[it.head:i]...)
it.head = i + 1
return buf, nil
return it.tmpBuffer, nil
} else if c == '\\' {
buf := append(it.tmpBuffer[:0], it.buffer[it.head:i]...)
it.head = i + 1
Expand All @@ -158,6 +157,7 @@ func (it *Iterator) readStringAsSlice() (_ []byte, err error) {
buf := append(it.tmpBuffer[:0], it.buffer[it.head:it.tail]...)
it.head = it.tail
if err := it.readMore(); err != nil {
it.tmpBuffer = buf
return nil, err
}
buf, err = it.readStringAsSliceSlow(buf)
Expand Down
3 changes: 2 additions & 1 deletion val_decoder_native_struct.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ func (df *decoderFields) add(f *field, dec ValDecoder) {
df.list = append(df.list, dfi)
}

// key and buf
func (df *decoderFields) find(key, buf []byte, caseSensitive bool) (*decoderFieldInfo, []byte) {
if i, ok := df.nameIndex[localByteToString(key)]; ok {
return &df.list[i], buf
Expand Down Expand Up @@ -126,7 +127,7 @@ func (dec *structDecoder) Decode(ptr unsafe.Pointer, it *Iterator, _ *DecOpts) (
if err != nil {
return err
}
stField, fieldOut := dec.fields.find(field, it.tmpBuffer, it.cfg.caseSensitive)
stField, fieldOut := dec.fields.find(field, field, it.cfg.caseSensitive)
it.tmpBuffer = fieldOut
if stField != nil {
curPtr := add(ptr, stField.offsets[0].val, "struct field")
Expand Down

0 comments on commit b7b9995

Please sign in to comment.