summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorRyan Lopopolo <[email protected]>2019-06-22 12:55:02 +0100
committerRyan Lopopolo <[email protected]>2019-06-22 12:55:02 +0100
commita932b8c96a4312753993ce0b98d2e9eedec17de0 (patch)
tree1cd0e89c55051497d469bcaaf0fdcd7f3a01fb5e
parent0f516bbe1dd61759faf2609970bd5cd855931221 (diff)
downloadmruby-a932b8c96a4312753993ce0b98d2e9eedec17de0.tar.gz
mruby-a932b8c96a4312753993ce0b98d2e9eedec17de0.zip
Speed up base case by 2x
Make non-paragraph mode twice as fast. Performance is within a factor of 2 of the original implementation.
-rw-r--r--mrblib/string.rb11
1 files changed, 2 insertions, 9 deletions
diff --git a/mrblib/string.rb b/mrblib/string.rb
index adf19d00c..0bac52a20 100644
--- a/mrblib/string.rb
+++ b/mrblib/string.rb
@@ -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