mirror of
https://github.com/mruby/mruby
synced 2026-06-08 16:11:16 +00:00
Speed up base case by 2x
Make non-paragraph mode twice as fast. Performance is within a factor of 2 of the original implementation.
This commit is contained in:
+2
-9
@@ -44,20 +44,13 @@ class String
|
||||
pointer += 1
|
||||
end
|
||||
else
|
||||
matched_length = 0
|
||||
separator_length = separator.length
|
||||
while pointer < string.length
|
||||
c = string[pointer]
|
||||
pointer += 1
|
||||
matched_length += 1 if c == separator[matched_length]
|
||||
next unless matched_length == separator_length
|
||||
|
||||
while (pointer = string.index(separator, start))
|
||||
pointer += separator.length
|
||||
if self.class == String
|
||||
yield string[start...pointer]
|
||||
else
|
||||
yield self.class.new(string[start...pointer])
|
||||
end
|
||||
matched_length = 0
|
||||
start = pointer
|
||||
end
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user