Skip to content

Commit

Permalink
Avoid strings.Split to reduce allocation
Browse files Browse the repository at this point in the history
  • Loading branch information
itchyny committed Sep 3, 2020
1 parent 2e65b01 commit e268038
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 6 deletions.
7 changes: 4 additions & 3 deletions decode.go
Expand Up @@ -102,9 +102,10 @@ func Unmarshal(data []byte, v interface{}) error {
ft := t.Field(i)
fv := rv.Field(i)

tag := ft.Tag.Get("ltsv")
tags := strings.Split(tag, ",")
key := tags[0]
key := ft.Tag.Get("ltsv")
if i := strings.IndexByte(key, ','); i >= 0 {
key = key[:i]
}
if key == "-" {
continue
}
Expand Down
7 changes: 4 additions & 3 deletions encode.go
Expand Up @@ -66,9 +66,10 @@ func makeStructWriter(v reflect.Value) fieldWriter {
writers := make([]fieldWriter, n)
for i := 0; i < n; i++ {
ft := t.Field(i)
tag := ft.Tag.Get("ltsv")
tags := strings.Split(tag, ",")
key := tags[0]
key := ft.Tag.Get("ltsv")
if i := strings.IndexByte(key, ','); i >= 0 {
key = key[:i]
}
if key == "-" {
continue
}
Expand Down

0 comments on commit e268038

Please sign in to comment.