Skip to content

Commit

Permalink
Speed up reduce slightly.
Browse files Browse the repository at this point in the history
  • Loading branch information
candid82 committed Jul 29, 2023
1 parent ea1b8e5 commit a9935b1
Showing 1 changed file with 14 additions and 4 deletions.
18 changes: 14 additions & 4 deletions core/object.go
Original file line number Diff line number Diff line change
Expand Up @@ -1807,9 +1807,14 @@ func CountedIndexedReduce(v CountedIndexed, c Callable) Object {
case 1:
return v.At(0)
default:
acc := c.Call([]Object{v.At(0), v.At(1)})
args := make([]Object, 2)
args[0] = v.At(0)
args[1] = v.At(1)
acc := c.Call(args)
for i := 2; i < v.Count(); i++ {
acc = c.Call([]Object{acc, v.At(i)})
args[0] = acc
args[1] = v.At(i)
acc = c.Call(args)
}
return acc
}
Expand All @@ -1820,9 +1825,14 @@ func CountedIndexedReduceInit(v CountedIndexed, c Callable, init Object) Object
case 0:
return init
default:
acc := c.Call([]Object{init, v.At(0)})
args := make([]Object, 2)
args[0] = init
args[1] = v.At(0)
acc := c.Call(args)
for i := 1; i < v.Count(); i++ {
acc = c.Call([]Object{acc, v.At(i)})
args[0] = acc
args[1] = v.At(i)
acc = c.Call(args)
}
return acc
}
Expand Down

0 comments on commit a9935b1

Please sign in to comment.