Skip to content

Commit

Permalink
Optimise some Seq::Array methods.
Browse files Browse the repository at this point in the history
  • Loading branch information
Arlen Christian Mart Cuss committed Dec 12, 2012
1 parent 8e7de65 commit c344af9
Showing 1 changed file with 23 additions and 1 deletion.
24 changes: 23 additions & 1 deletion lib/rouge/seq.rb
Expand Up @@ -64,7 +64,9 @@ def length
len len
end end


alias count length def count
length
end


def [](idx) def [](idx)
return to_a[idx] if idx.is_a? Range return to_a[idx] if idx.is_a? Range
Expand Down Expand Up @@ -187,6 +189,26 @@ def next
Array.new(@array, @idx + 1) Array.new(@array, @idx + 1)
end end
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 end


# A lazy seq; contains the body (thunk) which is a lambda to get the "real" # A lazy seq; contains the body (thunk) which is a lambda to get the "real"
Expand Down

0 comments on commit c344af9

Please sign in to comment.