Skip to content

Commit

Permalink
fix processing group keys
Browse files Browse the repository at this point in the history
  • Loading branch information
RyougiNevermore committed Dec 21, 2023
1 parent 32b422c commit 30d0f5b
Showing 1 changed file with 14 additions and 9 deletions.
23 changes: 14 additions & 9 deletions config.go
Original file line number Diff line number Diff line change
Expand Up @@ -85,11 +85,7 @@ func (c Config) Freeze() API {
}

api.processingGroup = new(singleflight.Group)
api.processingGroupKeys = &sync.Pool{
New: func() any {
return make([]byte, 64)
},
}
api.processingGroupKeys = &sync.Pool{}

return api
}
Expand Down Expand Up @@ -297,7 +293,12 @@ func (c *frozenConfig) getProcessingEncoderFromCache(fingerprint [32]byte, rtype
}

func (c *frozenConfig) borrowProcessEncoderGroupKey(schema Schema, typ reflect2.Type) (key []byte) {
key = c.processingGroupKeys.Get().([]byte)
k := c.processingGroupKeys.Get()
if k != nil {
key = k.([]byte)
} else {
key = make([]byte, 64)
}
fingerprint := schema.Fingerprint()
copy(key[:32], fingerprint[:])
binary.LittleEndian.PutUint64(key[32:], uint64(typ.RType()))
Expand All @@ -312,7 +313,12 @@ func (c *frozenConfig) borrowProcessEncoderGroupKey(schema Schema, typ reflect2.
}

func (c *frozenConfig) borrowProcessDecoderGroupKey(schema Schema, typ reflect2.Type) (key []byte) {
key = c.processingGroupKeys.Get().([]byte)
k := c.processingGroupKeys.Get()
if k != nil {
key = k.([]byte)
} else {
key = make([]byte, 64)
}
fingerprint := schema.Fingerprint()
copy(key[:32], fingerprint[:])
binary.LittleEndian.PutUint64(key[32:], uint64(typ.RType()))
Expand All @@ -328,8 +334,7 @@ func (c *frozenConfig) borrowProcessDecoderGroupKey(schema Schema, typ reflect2.

func (c *frozenConfig) returnProcessGroupKey(key []byte) {
c.processingGroup.Forget(*(*string)(unsafe.Pointer(&key)))
c.processingGroupKeys.Put(key)
return
c.processingGroupKeys.Put(key[:])

Check failure on line 337 in config.go

View workflow job for this annotation

GitHub Actions / test (1.20)

unslice: could simplify key[:] to key (gocritic)
}

func (c *frozenConfig) getTagKey() string {
Expand Down

0 comments on commit 30d0f5b

Please sign in to comment.