Method Link>>at: inefficiency

Project:GNU Smalltalk
Component:Base classes
Category:bug
Priority:normal
Assigned:Unassigned
Status:fixed
Description

Not a bug, but inefficiency. Method Link>>at: for negative indexes scans the entire list. My solution is:

  at: index [
     |i|
     index<1 ifFalse: [
        i := 1.
        self do: [:element| i=index ifTrue: [ ^element ]. i:=i+1 ]
     ].
     SystemExceptions.IndexOutOfRange signalOn: self withIndex: index
  ]

Updates

#1 submitted by Paolo Bonzini on Mon, 10/08/2012 - 15:54
Status:active» fixed

Applied at last, thanks.

User login