Skip to content

Commit

Permalink
make more efficient
Browse files Browse the repository at this point in the history
  • Loading branch information
jimjbrettj committed Aug 28, 2024
1 parent d04282d commit 566a546
Showing 1 changed file with 7 additions and 7 deletions.
14 changes: 7 additions & 7 deletions lib/runtime/storage/storagediff.go
Original file line number Diff line number Diff line change
Expand Up @@ -141,17 +141,17 @@ func (cs *storageDiff) clearPrefixInChild(keyToChild string, prefix []byte,
// optional limit. It returns the number of keys deleted and a boolean
// indicating if all keys with the prefix were removed.
func (cs *storageDiff) clearPrefix(prefix []byte, trieKeys []string, limit int) (deleted uint32, allDeleted bool) {
allKeys := slices.Clone(trieKeys)
newKeys := maps.Keys(cs.upserts)
for _, k := range newKeys {
if !slices.Contains(allKeys, k) {
allKeys = append(allKeys, k)
keysToClear := newKeys
for _, k := range trieKeys {
if _, ok := cs.upserts[k]; !ok {
keysToClear = append(keysToClear, k)
}
}

deleted = 0
sort.Strings(allKeys)
for _, k := range allKeys {
sort.Strings(keysToClear)
for _, k := range keysToClear {
if limit == 0 {
break
}
Expand All @@ -165,7 +165,7 @@ func (cs *storageDiff) clearPrefix(prefix []byte, trieKeys []string, limit int)
}
}

return deleted, deleted == uint32(len(allKeys))
return deleted, deleted == uint32(len(keysToClear))
}

// getFromChild attempts to retrieve a value associated with a specific key
Expand Down

0 comments on commit 566a546

Please sign in to comment.