Skip to content
This repository has been archived by the owner. It is now read-only.
Permalink
Browse files

Short-circuit checked bytes allocation in Identifier Pool. (#154)

  • Loading branch information...
prateek committed May 4, 2018
1 parent 91b27f4 commit 2e6f610c6d1dca2e51bb1b203c9a7322941fe558
Showing with 16 additions and 8 deletions.
  1. +16 −8 ident/identifier_pool.go
@@ -118,17 +118,25 @@ func (p *simplePool) StringTag(name string, value string) Tag {
}
}

func (p *simplePool) cloneBytes(b []byte) checked.Bytes {
newData := p.bytesPool.Get(len(b))
newData.IncRef()
newData.AppendAll(b)
return newData
}

func (p *simplePool) Clone(existing ID) ID {
id := p.pool.Get().(*id)

data := existing.Data()
data.IncRef()

newData := p.bytesPool.Get(data.Len())
newData.IncRef()
newData.AppendAll(data.Bytes())

data.DecRef()
var newData checked.Bytes
if idBytes, ok := existing.(BytesID); ok {
newData = p.cloneBytes(idBytes)
} else {
data := existing.Data()
data.IncRef()
newData = p.cloneBytes(data.Bytes())
data.DecRef()
}

id.pool, id.data = p, newData

0 comments on commit 2e6f610

Please sign in to comment.
You can’t perform that action at this time.