Skip to content

Commit 3d5ad3f

Browse files
committed
[Truffle] Pulled in String#sum from Rubinius.
1 parent 25a64b4 commit 3d5ad3f

File tree

2 files changed

+13
-3
lines changed

2 files changed

+13
-3
lines changed

spec/truffle/tags/core/string/sum_tags.txt

Lines changed: 0 additions & 3 deletions
This file was deleted.

truffle/src/main/ruby/core/rubinius/common/string.rb

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,19 @@ def slice!(one, two=undefined)
9797
result
9898
end
9999

100+
def sum(bits=16)
101+
bits = Rubinius::Type.coerce_to bits, Fixnum, :to_int
102+
i = -1
103+
sum = 0
104+
105+
sum += @data[i] while (i += 1) < @num_bytes
106+
if bits > 0
107+
sum & ((1 << bits) - 1)
108+
else
109+
sum
110+
end
111+
end
112+
100113
def to_c
101114
Complexifier.new(self).convert
102115
end

0 commit comments

Comments
 (0)