mirror of
https://github.com/rs/zerolog
synced 2026-06-08 17:13:30 +00:00
fix: return dict to Event pool (#749)
Return dict to event pool in Array.Dict()
This commit is contained in:
@@ -827,4 +827,4 @@ references to them from within any `MarshalZerologArray(a *Array)` callback (e.g
|
||||
own code as they will be cleared and returned to the pool after being buffered by a call to `Context.Array()` or `Event.Array()`.
|
||||
|
||||
Any _dictionary_ `Event` returned from `Context.CreateDict()` or `Event.CreateDict()` **must not** be referenced after being
|
||||
buffered by a call to `Context.Dict()` or `Event.Dict()` as they will be cleared and returned to the pool.
|
||||
buffered by a call to `Array.Dict()`, `Context.Dict()`, or `Event.Dict()` as they will be cleared and returned to the pool.
|
||||
|
||||
@@ -265,6 +265,7 @@ func (a *Array) MACAddr(ha net.HardwareAddr) *Array {
|
||||
func (a *Array) Dict(dict *Event) *Array {
|
||||
dict.buf = enc.AppendEndMarker(dict.buf)
|
||||
a.buf = append(enc.AppendArrayDelim(a.buf), dict.buf...)
|
||||
putEvent(dict)
|
||||
return a
|
||||
}
|
||||
|
||||
|
||||
@@ -180,11 +180,10 @@ func (e *Event) Fields(fields interface{}) *Event {
|
||||
// Dict adds the field key with a dict to the event context.
|
||||
// Use e.CreateDict() to create the dictionary.
|
||||
func (e *Event) Dict(key string, dict *Event) *Event {
|
||||
if e == nil {
|
||||
return e
|
||||
if e != nil {
|
||||
dict.buf = enc.AppendEndMarker(dict.buf)
|
||||
e.buf = append(enc.AppendKey(e.buf, key), dict.buf...)
|
||||
}
|
||||
dict.buf = enc.AppendEndMarker(dict.buf)
|
||||
e.buf = append(enc.AppendKey(e.buf, key), dict.buf...)
|
||||
putEvent(dict)
|
||||
return e
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user