Skip to content

Commit

Permalink
chore(lib/runtime): DeleteChildLimit calls Entries once instead of …
Browse files Browse the repository at this point in the history
…3 times
  • Loading branch information
qdm12 committed Nov 4, 2022
1 parent 918435f commit 05627b9
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 4 deletions.
7 changes: 4 additions & 3 deletions lib/runtime/storage/trie.go
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,8 @@ func (s *TrieState) DeleteChildLimit(key []byte, limit *[]byte) (
return 0, false, err
}

qtyEntries := uint32(len(tr.Entries()))
childTrieEntries := tr.Entries()
qtyEntries := uint32(len(childTrieEntries))
if limit == nil {
err = s.t.DeleteChild(key)
if err != nil {
Expand All @@ -200,8 +201,8 @@ func (s *TrieState) DeleteChildLimit(key []byte, limit *[]byte) (
}
limitUint := binary.LittleEndian.Uint32(*limit)

keys := make([]string, 0, len(tr.Entries()))
for k := range tr.Entries() {
keys := make([]string, 0, qtyEntries)
for k := range childTrieEntries {
keys = append(keys, k)
}
sort.Strings(keys)
Expand Down
2 changes: 1 addition & 1 deletion lib/runtime/wasmer/imports_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1502,7 +1502,7 @@ func Test_ext_default_child_storage_storage_kill_version_2_limit_all(t *testing.

child, err = inst.ctx.Storage.GetChild(testChildKey)
require.NoError(t, err)
require.Equal(t, 0, len(child.Entries()))
require.Empty(t, child.Entries())
}

func Test_ext_default_child_storage_storage_kill_version_2_limit_1(t *testing.T) {
Expand Down

0 comments on commit 05627b9

Please sign in to comment.