Fix VM memory allocation optimizations by reducing what we allocate on the heap
This commit is contained in:
@@ -20,7 +20,7 @@ func Find(args ...object.Object) object.Object {
|
||||
}
|
||||
|
||||
// find substring in string
|
||||
if haystack, ok := args[0].(*object.String); ok {
|
||||
if haystack, ok := args[0].(object.String); ok {
|
||||
if err := typing.Check(
|
||||
"find", args,
|
||||
typing.WithTypes(object.StringType, object.StringType),
|
||||
@@ -28,9 +28,9 @@ func Find(args ...object.Object) object.Object {
|
||||
return newError(err.Error())
|
||||
}
|
||||
|
||||
needle := args[1].(*object.String)
|
||||
needle := args[1].(object.String)
|
||||
index := strings.Index(haystack.Value, needle.Value)
|
||||
return &object.Integer{Value: int64(index)}
|
||||
return object.Integer{Value: int64(index)}
|
||||
}
|
||||
|
||||
// find in array
|
||||
@@ -40,9 +40,9 @@ func Find(args ...object.Object) object.Object {
|
||||
return needle.Compare(haystack.Elements[i]) == 0
|
||||
})
|
||||
if i < len(haystack.Elements) && needle.Compare(haystack.Elements[i]) == 0 {
|
||||
return &object.Integer{Value: int64(i)}
|
||||
return object.Integer{Value: int64(i)}
|
||||
}
|
||||
return &object.Integer{Value: -1}
|
||||
return object.Integer{Value: -1}
|
||||
}
|
||||
|
||||
return newError(
|
||||
|
||||
Reference in New Issue
Block a user