Skip to content

Commit

Permalink
refactor: minor performance improvements
Browse files Browse the repository at this point in the history
  • Loading branch information
wI2L committed Mar 12, 2020
1 parent aa59591 commit 1ef26b4
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 6 deletions.
8 changes: 4 additions & 4 deletions encode.go
Original file line number Diff line number Diff line change
Expand Up @@ -208,7 +208,8 @@ fieldLoop:
// Find the nested struct field by following
// the offset sequence, indirecting encountered
// pointers as needed.
for _, s := range f.embedSeq {
for i := 0; i < len(f.embedSeq); i++ {
s := &f.embedSeq[i]
v = unsafe.Pointer(uintptr(v) + s.offset)
if s.indir {
if v = *(*unsafe.Pointer)(v); v == nil {
Expand All @@ -231,10 +232,9 @@ fieldLoop:
if f.omitEmpty && f.empty(v) {
continue
}
key = f.keyEscHTML
if noHTMLEscape {
key = f.keyNonEsc
} else {
key = f.keyEscHTML
}
dst = append(dst, nxt)
nxt = ','
Expand Down Expand Up @@ -816,7 +816,7 @@ func appendEscapedBytes(dst []byte, b []byte, opts encOpts) []byte {
noCoerce := opts.flags.has(noUTF8Coercion)
noEscape := opts.flags.has(noHTMLEscaping)

for i < len(b) {
for len(b) > i {
if c := b[i]; c < utf8.RuneSelf {
if isSafeJSONChar(c) && (noEscape || !isHTMLChar(c)) {
// If the current character doesn't need
Expand Down
4 changes: 2 additions & 2 deletions options.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@ type Option func(*encOpts)

type bitmask uint64

func (b *bitmask) set(f bitmask) { *b |= f }
func (b *bitmask) has(f bitmask) bool { return *b&f != 0 }
func (b *bitmask) set(f bitmask) { *b |= f }
func (b bitmask) has(f bitmask) bool { return b&f != 0 }

const (
unixTime bitmask = 1 << iota
Expand Down

0 comments on commit 1ef26b4

Please sign in to comment.