Skip to content

Commit

Permalink
Merge pull request #2618 from onflow/bastian/use-ordered-map-has
Browse files Browse the repository at this point in the history
  • Loading branch information
turbolent authored Jun 29, 2023
2 parents 79f44a1 + f578f57 commit 5ff23cf
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 13 deletions.
8 changes: 2 additions & 6 deletions runtime/interpreter/storagemap.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,20 +67,16 @@ func NewStorageMapWithRootID(storage atree.SlabStorage, storageID atree.StorageI

// ValueExists returns true if the given key exists in the storage map.
func (s StorageMap) ValueExists(key StorageMapKey) bool {
_, err := s.orderedMap.Get(
exists, err := s.orderedMap.Has(
key.AtreeValueCompare,
key.AtreeValueHashInput,
key.AtreeValue(),
)
if err != nil {
var keyNotFoundError *atree.KeyNotFoundError
if goerrors.As(err, &keyNotFoundError) {
return false
}
panic(errors.NewExternalError(err))
}

return true
return exists
}

// ReadValue returns the value for the given key.
Expand Down
9 changes: 2 additions & 7 deletions runtime/interpreter/value.go
Original file line number Diff line number Diff line change
Expand Up @@ -16925,20 +16925,15 @@ func (v *DictionaryValue) ContainsKey(
valueComparator := newValueComparator(interpreter, locationRange)
hashInputProvider := newHashInputProvider(interpreter, locationRange)

_, err := v.dictionary.Get(
exists, err := v.dictionary.Has(
valueComparator,
hashInputProvider,
keyValue,
)
if err != nil {
var keyNotFoundError *atree.KeyNotFoundError
if goerrors.As(err, &keyNotFoundError) {
return FalseValue
}
panic(errors.NewExternalError(err))
}

return TrueValue
return AsBoolValue(exists)
}

func (v *DictionaryValue) Get(
Expand Down

0 comments on commit 5ff23cf

Please sign in to comment.