Skip to content

Commit

Permalink
Optimized String#rindex(Char) when Char is ASCII
Browse files Browse the repository at this point in the history
Ary Borenszweig committed Jul 12, 2016

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
1 parent 177828e commit 4dfc24a
Showing 1 changed file with 10 additions and 0 deletions.
10 changes: 10 additions & 0 deletions src/string.cr
Original file line number Diff line number Diff line change
@@ -2055,6 +2055,16 @@ class String
offset += size if offset < 0
return nil if offset < 0

# If it's ASCII we can search from the end
if search.ord < 0x80
offset.downto(0) do |i|
if to_unsafe[i] == search.ord
return i
end
end
return nil
end

last_index = nil

each_char_with_index do |char, i|

0 comments on commit 4dfc24a

Please sign in to comment.