On Thu, 14 Sep 2017 18:03:16 -0700, alex.jakime...@gmail.com wrote:
> Actually, another direct implication of using .first is this:
> 
> Code:
> enum Animal (Cat => 0, Dog => 0, Human => 42);
> say Dog.succ
> 
> Result:
> Dog
> 
> 
> So it's not just the algorithmic complexity, and we need a test for that.
> 
> On 2017-09-14 17:47:59, alex.jakime...@gmail.com wrote:
> > Source code:
> > https://github.com/rakudo/rakudo/blob/nom/src/core/Enumeration.pm#L36-
> > L45
> >
> > The problem is with this line:
> > my $index = @values.first( self, :k );
> >
> > Basically, .first will iterate through the elements, but I guess it is
> > possible to store the index of the current enum value and simply
> > increment/decrement it when needed.
> >
> > Some discussion here:
> > https://github.com/rakudo/rakudo/pull/1156#issuecomment-329640201
> >
> > I think this ticket is closable without tests once the change is
> > implemented.


The wrong Enumeration:D being returned is now fixed[^1][^2] and tested[^3].

For the performance issue: I made[^4] .pred 8.4x faster and .succ 6x faster, 
while keeping the same O(). I hope that's sufficient compromise to close this 
ticket, given that the huge majority of Enumerations would have just a few 
elements, not thousands.

[1] https://github.com/rakudo/rakudo/commit/69dae1f3be
[2] https://github.com/rakudo/rakudo/commit/8d938461a9
[3] https://github.com/perl6/roast/commit/dfbbd70d46
[4] https://github.com/rakudo/rakudo/commit/55aa7f28d3

Reply via email to