Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Speed up some easy case for Array#*

  • Loading branch information...
commit ae12f7fabc19a61938ab072a2170efe3b2cf2265 1 parent 6f6e4e4
Evan Phoenix authored
Showing with 18 additions and 1 deletion.
  1. +18 −1 kernel/common/array.rb
View
19 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
Please sign in to comment.
Something went wrong with that request. Please try again.