mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-07-22 12:46:44 +00:00
core/rawdb: simplify the size counting
This commit is contained in:
parent
9c55041750
commit
b40a9b85ad
1 changed files with 9 additions and 20 deletions
|
|
@ -91,15 +91,14 @@ func (t *memoryTable) truncateHead(items uint64) error {
|
||||||
if items < t.offset {
|
if items < t.offset {
|
||||||
return errors.New("truncation below tail")
|
return errors.New("truncation below tail")
|
||||||
}
|
}
|
||||||
removeFrom := items - t.offset
|
for i := int(items - t.offset); i < len(t.data); i++ {
|
||||||
for i := int(removeFrom); i < len(t.data); i++ {
|
|
||||||
if t.size > uint64(len(t.data[i])) {
|
if t.size > uint64(len(t.data[i])) {
|
||||||
t.size -= uint64(len(t.data[i]))
|
t.size -= uint64(len(t.data[i]))
|
||||||
} else {
|
} else {
|
||||||
t.size = 0
|
t.size = 0
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
t.data = t.data[:removeFrom]
|
t.data = t.data[:items-t.offset]
|
||||||
t.items = items
|
t.items = items
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
@ -116,25 +115,15 @@ func (t *memoryTable) truncateTail(items uint64) error {
|
||||||
if t.items < items {
|
if t.items < items {
|
||||||
return errors.New("truncation above head")
|
return errors.New("truncation above head")
|
||||||
}
|
}
|
||||||
drop := items - t.offset
|
for i := uint64(0); i < items-t.offset; i++ {
|
||||||
var removed uint64
|
if t.size > uint64(len(t.data[i])) {
|
||||||
for i := uint64(0); i < drop; i++ {
|
t.size -= uint64(len(t.data[i]))
|
||||||
removed += uint64(len(t.data[i]))
|
} else {
|
||||||
}
|
t.size = 0
|
||||||
newLen := uint64(len(t.data)) - drop
|
}
|
||||||
if newLen == 0 {
|
|
||||||
t.data = nil
|
|
||||||
} else {
|
|
||||||
newData := make([][]byte, newLen)
|
|
||||||
copy(newData, t.data[drop:])
|
|
||||||
t.data = newData
|
|
||||||
}
|
}
|
||||||
|
t.data = t.data[items-t.offset:]
|
||||||
t.offset = items
|
t.offset = items
|
||||||
if removed >= t.size {
|
|
||||||
t.size = 0
|
|
||||||
} else {
|
|
||||||
t.size -= removed
|
|
||||||
}
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue