Permalink
Browse files

Optimise some Seq::Array methods.

  • Loading branch information...
Arlen Christian Mart Cuss
Arlen Christian Mart Cuss committed Dec 12, 2012
1 parent 8e7de65 commit c344af9982004c6528273cf7d6940ae709d62b37
Showing with 23 additions and 1 deletion.
  1. +23 −1 lib/rouge/seq.rb
View
@@ -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"

0 comments on commit c344af9

Please sign in to comment.