Forum | Documentation | Website | Blog

Skip to content
Snippets Groups Projects
Commit c87ceba7 authored by Ary Borenszweig's avatar Ary Borenszweig
Browse files

Compute String#hash from bytes, not chars

parent 041209a2
Branches
Tags
...@@ -60,8 +60,14 @@ class Pointer(T) ...@@ -60,8 +60,14 @@ class Pointer(T)
self[i], self[j] = self[j], self[i] self[i], self[j] = self[j], self[i]
end end
def map(times, &block : T -> U) def each(count)
Array(U).new(times) { |i| yield self[i] } count.times do |i|
yield self[i]
end
end
def map(count, &block : T -> U)
Array(U).new(count) { |i| yield self[i] }
end end
def to_a(length) def to_a(length)
......
...@@ -505,6 +505,12 @@ class String ...@@ -505,6 +505,12 @@ class String
end end
end end
def each_byte
cstr.each(length) do |byte|
yield byte
end
end
def inspect def inspect
"\"#{dump}\"" "\"#{dump}\""
end end
...@@ -562,8 +568,8 @@ class String ...@@ -562,8 +568,8 @@ class String
def hash def hash
h = 0 h = 0
each_char do |c| each_byte do |c|
h = 31 * h + c.ord h = 31 * h + c
end end
h h
end end
......
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment