Skip to content

Commit

Permalink
switch clist back to list
Browse files Browse the repository at this point in the history
  • Loading branch information
ValarDragon committed Aug 11, 2018
1 parent 3f351cc commit a844c4a
Showing 1 changed file with 9 additions and 10 deletions.
19 changes: 9 additions & 10 deletions mempool/mempool.go
Expand Up @@ -2,6 +2,7 @@ package mempool

import (
"bytes"
"container/list"
"fmt"
"sync"
"sync/atomic"
Expand Down Expand Up @@ -487,8 +488,8 @@ type txCache interface {
type mapTxCache struct {
mtx sync.Mutex
size int
map_ map[string]*clist.CElement
list *clist.CList // to remove oldest tx when cache gets too big
map_ map[string]*list.Element
list *list.List // to remove oldest tx when cache gets too big
}

var _ txCache = (*mapTxCache)(nil)
Expand All @@ -497,15 +498,15 @@ var _ txCache = (*mapTxCache)(nil)
func newMapTxCache(cacheSize int) *mapTxCache {
return &mapTxCache{
size: cacheSize,
map_: make(map[string]*clist.CElement, cacheSize),
list: clist.New(),
map_: make(map[string]*list.Element, cacheSize),
list: list.New(),
}
}

// Reset resets the cache to an empty state.
func (cache *mapTxCache) Reset() {
cache.mtx.Lock()
cache.map_ = make(map[string]*clist.CElement, cache.size)
cache.map_ = make(map[string]*list.Element, cache.size)
cache.list.Init()
cache.mtx.Unlock()
}
Expand All @@ -525,8 +526,6 @@ func (cache *mapTxCache) Push(tx types.Tx) bool {
poppedTx := popped.Value.(types.Tx)
delete(cache.map_, string(poppedTx))
cache.list.Remove(popped)
popped.DetachPrev()
popped.DetachNext()
}
cache.list.PushBack(tx)
cache.map_[string(tx)] = cache.list.Back()
Expand All @@ -539,9 +538,9 @@ func (cache *mapTxCache) Remove(tx types.Tx) {
stx := string(tx)
popped := cache.map_[stx]
delete(cache.map_, stx)
cache.list.Remove(popped)
popped.DetachPrev()
popped.DetachNext()
if popped != nil {
cache.list.Remove(popped)
}

cache.mtx.Unlock()
}
Expand Down

0 comments on commit a844c4a

Please sign in to comment.