Minimize allocations due to heap escapes
This commit is contained in:
parent
8c9a308c9a
commit
8c5df03e14
|
@ -81,7 +81,7 @@ func GetRequestablePieces(input Input, pro *PieceRequestOrder, f func(ih metainf
|
|||
}
|
||||
var allTorrentsUnverifiedBytes int64
|
||||
pro.tree.Ascend(func(i btree.Item) bool {
|
||||
_i := i.(pieceRequestOrderItem)
|
||||
_i := i.(*pieceRequestOrderItem)
|
||||
ih := _i.key.InfoHash
|
||||
var t Torrent = input.Torrent(ih)
|
||||
var piece Piece = t.Piece(_i.key.Index)
|
||||
|
|
|
@ -35,8 +35,8 @@ type pieceRequestOrderItem struct {
|
|||
state PieceRequestOrderState
|
||||
}
|
||||
|
||||
func (me pieceRequestOrderItem) Less(other btree.Item) bool {
|
||||
otherConcrete := other.(pieceRequestOrderItem)
|
||||
func (me *pieceRequestOrderItem) Less(other btree.Item) bool {
|
||||
otherConcrete := other.(*pieceRequestOrderItem)
|
||||
return pieceOrderLess(
|
||||
pieceOrderInput{
|
||||
PieceRequestOrderState: me.state,
|
||||
|
@ -53,7 +53,7 @@ func (me *PieceRequestOrder) Add(key PieceRequestOrderKey, state PieceRequestOrd
|
|||
if _, ok := me.keys[key]; ok {
|
||||
panic(key)
|
||||
}
|
||||
if me.tree.ReplaceOrInsert(pieceRequestOrderItem{
|
||||
if me.tree.ReplaceOrInsert(&pieceRequestOrderItem{
|
||||
key: key,
|
||||
state: state,
|
||||
}) != nil {
|
||||
|
@ -63,13 +63,15 @@ func (me *PieceRequestOrder) Add(key PieceRequestOrderKey, state PieceRequestOrd
|
|||
}
|
||||
|
||||
func (me *PieceRequestOrder) Update(key PieceRequestOrderKey, state PieceRequestOrderState) {
|
||||
if me.tree.Delete(me.existingItemForKey(key)) == nil {
|
||||
item := me.existingItemForKey(key)
|
||||
if item.state == state {
|
||||
return
|
||||
}
|
||||
if me.tree.Delete(&item) == nil {
|
||||
panic(fmt.Sprintf("%#v", key))
|
||||
}
|
||||
if me.tree.ReplaceOrInsert(pieceRequestOrderItem{
|
||||
key: key,
|
||||
state: state,
|
||||
}) != nil {
|
||||
item.state = state
|
||||
if me.tree.ReplaceOrInsert(&item) != nil {
|
||||
panic(key)
|
||||
}
|
||||
me.keys[key] = state
|
||||
|
@ -83,7 +85,8 @@ func (me *PieceRequestOrder) existingItemForKey(key PieceRequestOrderKey) pieceR
|
|||
}
|
||||
|
||||
func (me *PieceRequestOrder) Delete(key PieceRequestOrderKey) {
|
||||
if me.tree.Delete(me.existingItemForKey(key)) == nil {
|
||||
item := me.existingItemForKey(key)
|
||||
if me.tree.Delete(&item) == nil {
|
||||
panic(key)
|
||||
}
|
||||
delete(me.keys, key)
|
||||
|
|
Loading…
Reference in New Issue