metadata: avoid allocations on delete

Signed-off-by: Vasiliy Tolstov <v.tolstov@unistack.org>
This commit is contained in:
Василий Толстов 2020-09-30 16:21:47 +03:00
parent 9c55b1d06a
commit 8532ccebba

View File

@ -28,7 +28,13 @@ func (md Metadata) Set(key, val string) {
}
func (md Metadata) Del(key string) {
delete(md, textproto.CanonicalMIMEHeaderKey(key))
// fast path
if _, ok := md[key]; ok {
delete(md, key)
} else {
// slow path
delete(md, textproto.CanonicalMIMEHeaderKey(key))
}
}
// Copy makes a copy of the metadata