Permalink
Browse files

Speed up some easy case for Array#*

  • Loading branch information...
1 parent 6f6e4e4 commit ae12f7fabc19a61938ab072a2170efe3b2cf2265 Evan Phoenix committed May 6, 2011
Showing with 18 additions and 1 deletion.
  1. +18 −1 kernel/common/array.rb
@@ -400,19 +400,36 @@ def *(multiplier)
raise ArgumentError, "Count cannot be negative" if multiplier < 0
+ case @total
+ when 0
+ # Edge case
+ out = self.class.allocate
+ out.taint if tainted?
+ return out
+ when 1
+ # Easy case
+ tuple = Rubinius::Tuple.pattern multiplier, at(0)
+ out = self.class.allocate
+ out.tuple = tuple
+ out.total = multiplier
+ out.taint if tainted?
+ return out
+ end
+
new_total = multiplier * @total
new_tuple = Rubinius::Tuple.new(new_total)
out = self.class.allocate
out.tuple = new_tuple
out.total = new_total
- out.taint if self.tainted? && multiplier > 0
+ out.taint if tainted?
offset = 0
while offset < new_total
new_tuple.copy_from @tuple, @start, @total, offset
offset += @total
end
+
out
end
end

0 comments on commit ae12f7f

Please sign in to comment.