From c344af9982004c6528273cf7d6940ae709d62b37 Mon Sep 17 00:00:00 2001 From: Arlen Christian Mart Cuss Date: Wed, 12 Dec 2012 14:07:39 +1100 Subject: [PATCH] Optimise some Seq::Array methods. --- lib/rouge/seq.rb | 24 +++++++++++++++++++++++- 1 file changed, 23 insertions(+), 1 deletion(-) diff --git a/lib/rouge/seq.rb b/lib/rouge/seq.rb index 8ffe30d..0134d78 100644 --- a/lib/rouge/seq.rb +++ b/lib/rouge/seq.rb @@ -64,7 +64,9 @@ def length len end - alias count length + def count + length + end def [](idx) return to_a[idx] if idx.is_a? Range @@ -187,6 +189,26 @@ def next Array.new(@array, @idx + 1) end end + + def length + @array.length - @idx + end + + def [](idx) + @array[@idx + idx] + end + + def to_a + @array[@idx..-1] + end + + def each(&block) + to_a.each(&block) + end + + def map(&block) + to_a.map(&block) + end end # A lazy seq; contains the body (thunk) which is a lambda to get the "real"