Skip to content

Commit

Permalink
Use ComputationKindLoop for internal array-value iterations
Browse files Browse the repository at this point in the history
  • Loading branch information
SupunS committed Oct 20, 2023
1 parent c16b00f commit c9ef8e3
Show file tree
Hide file tree
Showing 5 changed files with 12 additions and 13 deletions.
2 changes: 1 addition & 1 deletion runtime/common/computationkind.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ const (
ComputationKindCreateArrayValue
ComputationKindTransferArrayValue
ComputationKindDestroyArrayValue
ComputationKindIterateArrayValue
_
_
_
_
Expand Down
7 changes: 3 additions & 4 deletions runtime/common/computationkind_string.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions runtime/interpreter/value.go
Original file line number Diff line number Diff line change
Expand Up @@ -2997,7 +2997,7 @@ func (v *ArrayValue) Reverse(
}

// Meter computation for iterating the array.
interpreter.ReportComputation(common.ComputationKindIterateArrayValue, 1)
interpreter.ReportComputation(common.ComputationKindLoop, 1)

value := v.Get(interpreter, locationRange, index)
index--
Expand Down Expand Up @@ -3050,7 +3050,7 @@ func (v *ArrayValue) Filter(

for {
// Meter computation for iterating the array.
interpreter.ReportComputation(common.ComputationKindIterateArrayValue, 1)
interpreter.ReportComputation(common.ComputationKindLoop, 1)

atreeValue, err := iterator.Next()
if err != nil {
Expand Down Expand Up @@ -3146,7 +3146,7 @@ func (v *ArrayValue) Map(
func() Value {

// Meter computation for iterating the array.
interpreter.ReportComputation(common.ComputationKindIterateArrayValue, 1)
interpreter.ReportComputation(common.ComputationKindLoop, 1)

atreeValue, err := iterator.Next()
if err != nil {
Expand Down
2 changes: 1 addition & 1 deletion runtime/interpreter/value_string.go
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ func stringFunctionJoin(invocation Invocation) Value {
stringArray.Iterate(inter, func(element Value) (resume bool) {

// Meter computation for iterating the array.
inter.ReportComputation(common.ComputationKindIterateArrayValue, 1)
inter.ReportComputation(common.ComputationKindLoop, 1)

// Add separator
if !first {
Expand Down
8 changes: 4 additions & 4 deletions runtime/tests/interpreter/metering_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -424,7 +424,7 @@ func TestInterpretArrayFunctionsComputationMetering(t *testing.T) {
_, err = inter.Invoke("main")
require.NoError(t, err)

assert.Equal(t, uint(3), computationMeteredValues[common.ComputationKindIterateArrayValue])
assert.Equal(t, uint(3), computationMeteredValues[common.ComputationKindLoop])
})

t.Run("map", func(t *testing.T) {
Expand Down Expand Up @@ -452,7 +452,7 @@ func TestInterpretArrayFunctionsComputationMetering(t *testing.T) {
_, err = inter.Invoke("main")
require.NoError(t, err)

assert.Equal(t, uint(5), computationMeteredValues[common.ComputationKindIterateArrayValue])
assert.Equal(t, uint(5), computationMeteredValues[common.ComputationKindLoop])
})

t.Run("filter", func(t *testing.T) {
Expand Down Expand Up @@ -480,7 +480,7 @@ func TestInterpretArrayFunctionsComputationMetering(t *testing.T) {
_, err = inter.Invoke("main")
require.NoError(t, err)

assert.Equal(t, uint(6), computationMeteredValues[common.ComputationKindIterateArrayValue])
assert.Equal(t, uint(6), computationMeteredValues[common.ComputationKindLoop])
})
}

Expand Down Expand Up @@ -509,6 +509,6 @@ func TestInterpretStdlibComputationMetering(t *testing.T) {
_, err = inter.Invoke("main")
require.NoError(t, err)

assert.Equal(t, uint(4), computationMeteredValues[common.ComputationKindIterateArrayValue])
assert.Equal(t, uint(4), computationMeteredValues[common.ComputationKindLoop])
})
}

0 comments on commit c9ef8e3

Please sign in to comment.