Skip to content

Commit

Permalink
Use atree non-readonly iterators in some places
Browse files Browse the repository at this point in the history
Currently, we are not sure if all uses are readonly
in two functions, so this commit uses atree non-readonly
iterators in:
- CompositeValue.ForEachFieldName
- DictionaryValue.IterateKeys

Also added TODO to determine if all uses are readonly for these,
which would allow us to update comments and/or revert this change.
  • Loading branch information
fxamacker committed Apr 4, 2024
1 parent 3f70345 commit 8edcf7e
Showing 1 changed file with 14 additions and 2 deletions.
16 changes: 14 additions & 2 deletions runtime/interpreter/value.go
Original file line number Diff line number Diff line change
Expand Up @@ -17943,7 +17943,12 @@ func (v *CompositeValue) ForEachFieldName(
f func(fieldName string) (resume bool),
) {
iterate := func(fn atree.MapElementIterationFunc) error {
return v.dictionary.IterateReadOnlyKeys(
// Use NonReadOnlyIterator because we are not sure if it's guaranteed that
// all uses of CompositeValue.ForEachFieldName are only read-only.
// TODO: determine if all uses of CompositeValue.ForEachFieldName are read-only.
return v.dictionary.IterateKeys(
StringAtreeValueComparator,
StringAtreeValueHashInput,
fn,
)
}
Expand Down Expand Up @@ -18638,8 +18643,15 @@ func (v *DictionaryValue) IterateKeys(
locationRange LocationRange,
f func(key Value) (resume bool),
) {
valueComparator := newValueComparator(interpreter, locationRange)
hashInputProvider := newHashInputProvider(interpreter, locationRange)
iterate := func(fn atree.MapElementIterationFunc) error {
return v.dictionary.IterateReadOnlyKeys(
// Use NonReadOnlyIterator because we are not sure if f in
// all uses of DictionaryValue.IterateKeys are always read-only.
// TODO: determine if all uses of f are read-only.
return v.dictionary.IterateKeys(
valueComparator,
hashInputProvider,
fn,
)
}
Expand Down

0 comments on commit 8edcf7e

Please sign in to comment.