optimizations
This commit is contained in:
@@ -63,11 +63,8 @@ func (ao *Array) String() string {
|
||||
return ao.Inspect()
|
||||
}
|
||||
|
||||
func (ao *Array) Less(i, j int) bool {
|
||||
if cmp, ok := ao.Elements[i].(Comparable); ok {
|
||||
return cmp.Compare(ao.Elements[j]) == -1
|
||||
}
|
||||
return false
|
||||
func (a *Array) Less(i, j int) bool {
|
||||
return a.Elements[i].Compare(a.Elements[j]) == -1
|
||||
}
|
||||
|
||||
func (a *Array) Add(other Object) (Object, error) {
|
||||
@@ -129,18 +126,15 @@ func (ao *Array) Set(index, other Object) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (ao *Array) Compare(other Object) int {
|
||||
func (a *Array) Compare(other Object) int {
|
||||
if obj, ok := other.(*Array); ok {
|
||||
if len(ao.Elements) != len(obj.Elements) {
|
||||
if len(a.Elements) != len(obj.Elements) {
|
||||
return -1
|
||||
}
|
||||
for i, el := range ao.Elements {
|
||||
cmp, ok := el.(Comparable)
|
||||
if !ok {
|
||||
return -1
|
||||
}
|
||||
if cmp.Compare(obj.Elements[i]) != 0 {
|
||||
return cmp.Compare(obj.Elements[i])
|
||||
for i, el := range a.Elements {
|
||||
val := el.Compare(obj.Elements[i])
|
||||
if val != 0 {
|
||||
return val
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user