Skip to content

Commit c9009ba

Browse files
perf: pre-allocate slice capacity in evalRetrieve
Pre-allocate the slice capacity in `evalRetrieve` using `make([]result.Value, 0, len(got))` to avoid multiple reallocations as the slice grows. This is a standard optimization in Go when the maximum size of the resulting slice is known beforehand. Co-authored-by: suyashkumar <6299853+suyashkumar@users.noreply.github.com>
1 parent 8a5a5fa commit c9009ba

File tree

1 file changed

+1
-1
lines changed

1 file changed

+1
-1
lines changed

interpreter/expressions.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -191,7 +191,7 @@ func (i *interpreter) evalRetrieve(expr *model.Retrieve) (result.Value, error) {
191191
return result.Value{}, fmt.Errorf("internal error - retrieve result type should be a list of named types, got %v", listResultType)
192192
}
193193

194-
l := []result.Value{}
194+
l := make([]result.Value, 0, len(got))
195195
for _, c := range got {
196196
r, err := unwrapContained(c)
197197
if err != nil {

0 commit comments

Comments
 (0)