mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-07-26 14:46:42 +00:00
core/filtermaps: add fastCopy and fullCopy of filter maps
This commit is contained in:
parent
11e654e4d5
commit
cdaa79ada1
2 changed files with 17 additions and 5 deletions
|
|
@ -139,11 +139,23 @@ type FilterMaps struct {
|
||||||
// as transparent (uncached/unchanged).
|
// as transparent (uncached/unchanged).
|
||||||
type filterMap []FilterRow
|
type filterMap []FilterRow
|
||||||
|
|
||||||
// copy returns a copy of the given filter map. Note that the row slices are
|
// fastCopy returns a copy of the given filter map. Note that the row slices are
|
||||||
// copied but their contents are not. This permits extending the rows further
|
// copied but their contents are not. This permits appending to the rows further
|
||||||
// (which happens during map rendering) without affecting the validity of
|
// (which happens during map rendering) without affecting the validity of
|
||||||
// copies made for snapshots during rendering.
|
// copies made for snapshots during rendering.
|
||||||
func (fm filterMap) copy() filterMap {
|
// Appending to the rows of both the original map and the fast copy, or two fast
|
||||||
|
// copies of the same map would result in data corruption, therefore a fast copy
|
||||||
|
// should always be used in a read only way.
|
||||||
|
func (fm filterMap) fastCopy() filterMap {
|
||||||
|
c := make(filterMap, len(fm))
|
||||||
|
copy(c, fm)
|
||||||
|
return c
|
||||||
|
}
|
||||||
|
|
||||||
|
// fullCopy returns a copy of the given filter map, also making a copy of each
|
||||||
|
// individual filter row, ensuring that a modification to either one will never
|
||||||
|
// affect the other.
|
||||||
|
func (fm filterMap) fullCopy() filterMap {
|
||||||
c := make(filterMap, len(fm))
|
c := make(filterMap, len(fm))
|
||||||
for i, row := range fm {
|
for i, row := range fm {
|
||||||
c[i] = make(FilterRow, len(row))
|
c[i] = make(FilterRow, len(row))
|
||||||
|
|
|
||||||
|
|
@ -104,7 +104,7 @@ func (f *FilterMaps) renderMapsFromSnapshot(cp *renderedMap) (*mapRenderer, erro
|
||||||
return &mapRenderer{
|
return &mapRenderer{
|
||||||
f: f,
|
f: f,
|
||||||
currentMap: &renderedMap{
|
currentMap: &renderedMap{
|
||||||
filterMap: cp.filterMap.copy(),
|
filterMap: cp.filterMap.fullCopy(),
|
||||||
mapIndex: cp.mapIndex,
|
mapIndex: cp.mapIndex,
|
||||||
lastBlock: cp.lastBlock,
|
lastBlock: cp.lastBlock,
|
||||||
blockLvPtrs: cp.blockLvPtrs,
|
blockLvPtrs: cp.blockLvPtrs,
|
||||||
|
|
@ -260,7 +260,7 @@ func (r *mapRenderer) makeSnapshot() {
|
||||||
panic("iterator state inconsistent with last block")
|
panic("iterator state inconsistent with last block")
|
||||||
}
|
}
|
||||||
r.f.renderSnapshots.Add(r.currentMap.lastBlock, &renderedMap{
|
r.f.renderSnapshots.Add(r.currentMap.lastBlock, &renderedMap{
|
||||||
filterMap: r.currentMap.filterMap.copy(),
|
filterMap: r.currentMap.filterMap.fastCopy(),
|
||||||
mapIndex: r.currentMap.mapIndex,
|
mapIndex: r.currentMap.mapIndex,
|
||||||
lastBlock: r.currentMap.lastBlock,
|
lastBlock: r.currentMap.lastBlock,
|
||||||
lastBlockId: r.f.targetView.getBlockId(r.currentMap.lastBlock),
|
lastBlockId: r.f.targetView.getBlockId(r.currentMap.lastBlock),
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue