Fix VM memory allocation optimizations by reducing what we allocate on the heap
This commit is contained in:
@@ -25,7 +25,7 @@ func (ao *Array) PopLeft() Object {
|
||||
ao.Elements = ao.Elements[1:]
|
||||
return e
|
||||
}
|
||||
return &Null{}
|
||||
return Null{}
|
||||
}
|
||||
|
||||
func (ao *Array) PopRight() Object {
|
||||
@@ -34,7 +34,7 @@ func (ao *Array) PopRight() Object {
|
||||
ao.Elements = ao.Elements[:(len(ao.Elements) - 1)]
|
||||
return e
|
||||
}
|
||||
return &Null{}
|
||||
return Null{}
|
||||
}
|
||||
|
||||
func (ao *Array) Prepend(obj Object) {
|
||||
@@ -89,7 +89,7 @@ func (ao *Array) Mul(other Object) (Object, error) {
|
||||
}
|
||||
|
||||
var elements []Object
|
||||
N := int(other.(*Integer).Value)
|
||||
N := int(other.(Integer).Value)
|
||||
for i := 0; i < N; i++ {
|
||||
elements = append(elements, ao.Elements...)
|
||||
}
|
||||
@@ -102,10 +102,10 @@ func (ao *Array) Get(index Object) (Object, error) {
|
||||
return nil, fmt.Errorf("invalid type for array index, expected Integer got %s", index.Type())
|
||||
}
|
||||
|
||||
i := index.(*Integer).Value
|
||||
i := index.(Integer).Value
|
||||
N := int64(len(ao.Elements))
|
||||
if i < 0 || i >= N {
|
||||
return &Null{}, nil
|
||||
return Null{}, nil
|
||||
}
|
||||
|
||||
return ao.Elements[i], nil
|
||||
@@ -116,7 +116,7 @@ func (ao *Array) Set(index, other Object) error {
|
||||
return fmt.Errorf("invalid type for array index, expected Integer got %s", index.Type())
|
||||
}
|
||||
|
||||
i := index.(*Integer).Value
|
||||
i := index.(Integer).Value
|
||||
N := int64(len(ao.Elements))
|
||||
if i < 0 || i >= N {
|
||||
return fmt.Errorf("index out of bounds %d with array length %d", i, N)
|
||||
|
||||
Reference in New Issue
Block a user