Skip to content

Commit

Permalink
remove double slicing
Browse files Browse the repository at this point in the history
  • Loading branch information
rachel-bousfield committed Jan 30, 2024
1 parent 189e64e commit 88a5560
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 10 deletions.
8 changes: 1 addition & 7 deletions arbos/programs/native.go
Original file line number Diff line number Diff line change
Expand Up @@ -256,13 +256,7 @@ func accountBalanceImpl(api usize, address bytes20, cost *u64) bytes32 {
func accountCodeImpl(api usize, output *rustBytes, address bytes20, offset u32, size u32, cost *u64) {
closures := getApi(api)
code, gas := closures.accountCode(address.toAddress(), uint32(offset), uint32(size), uint64(*cost))
if int(offset) < len(code) {
end := int(offset + size)
if len(code) < end {
end = len(code)
}
output.setBytes(code[offset:end])
}
output.setBytes(code)
*cost = u64(gas)
}

Expand Down
4 changes: 2 additions & 2 deletions util/arbmath/bits.go
Original file line number Diff line number Diff line change
Expand Up @@ -89,9 +89,9 @@ func NonNilSlice[T any](slice []T) []T {
}

// Equivalent to slice[start:offset], but truncates when out of bounds rather than panicking.
func SliceWithRunoff[S any, I Integer](slice []S, start I, end I) []S {
func SliceWithRunoff[S any, I Integer](slice []S, start, end I) []S {
len := I(len(slice))
start = MinInt(start, 0)
start = MaxInt(start, 0)
end = MaxInt(start, end)

if slice == nil || start >= len {
Expand Down
3 changes: 2 additions & 1 deletion util/arbmath/math_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (
"math/rand"
"testing"

"github.com/ethereum/go-ethereum/common"
"github.com/offchainlabs/nitro/util/testhelpers"
)

Expand Down Expand Up @@ -100,7 +101,7 @@ func TestSlices(t *testing.T) {
assert_eq := func(left, right []uint8) {
t.Helper()
if !bytes.Equal(left, right) {
Fail(t)
Fail(t, common.Bytes2Hex(left), " ", common.Bytes2Hex(right))
}
}

Expand Down

0 comments on commit 88a5560

Please sign in to comment.