Skip to content

Commit 3ddbe1f

Browse files
committed
doEval(): preallocate a slice of values with required length
1 parent 404fc47 commit 3ddbe1f

File tree

1 file changed

+3
-3
lines changed

1 file changed

+3
-3
lines changed

kernel.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -445,13 +445,13 @@ func doEval(ir *interp.Interp, code string) (val []interface{}, err error) {
445445

446446
// Count the number of non-nil values in the output. If they are all nil then the output is skipped.
447447
nonNilCount := 0
448-
var values []interface{}
449-
for _, result := range results {
448+
values := make([]interface{}, len(results))
449+
for i, result := range results {
450450
val := base.ValueInterface(result)
451451
if val != nil {
452452
nonNilCount++
453453
}
454-
values = append(values, val)
454+
values[i] = val
455455
}
456456

457457
if nonNilCount > 0 {

0 commit comments

Comments
 (0)