1
0
Fork 0
mirror of https://github.com/moby/moby.git synced 2022-11-09 12:21:53 -05:00
moby--moby/daemon/logger/logger_test.go
Aaron Lehmann b642b3f21f Avoid using a map for log attributes
Having a map per log entry seemed heavier than necessary. These
attributes end up being sorted and serialized, so storing them in a map
doesn't add anything (there's no random access element). In SwarmKit,
they originate as a slice, so there's an unnecessary conversion to a map
and back.

This also fixes the sort comparator, which used to inefficiently split
the string on each comparison.

Signed-off-by: Aaron Lehmann <aaron.lehmann@docker.com>
2017-07-18 19:01:20 -07:00

21 lines
383 B
Go

package logger
import (
"github.com/docker/docker/api/types/backend"
)
func (m *Message) copy() *Message {
msg := &Message{
Source: m.Source,
Partial: m.Partial,
Timestamp: m.Timestamp,
}
if m.Attrs != nil {
msg.Attrs = make([]backend.LogAttr, len(m.Attrs))
copy(msg.Attrs, m.Attrs)
}
msg.Line = append(make([]byte, 0, len(m.Line)), m.Line...)
return msg
}