Skip to content

Commit 4bef4c2

Browse files
authored
fix: Improve the performance of the CONTENT_PATTERN regex in RSS parser to avoid backtracking issues. (#67)
This improves the performance of the XML stylesheet parsing a good amount. `RSS::Parser.parse` on `<?xml-stylesheet aaaa…=?>`, Ruby 3.4.9: | n (chars) | before (HEAD) | after (fix) | speedup | |-----------|--------------:|------------:|--------:| | 10,000 | 0.131 s | 0.0004 s | ~330× | | 20,000 | 0.508 s | 0.0003 s | ~1,600× | | 40,000 | 1.966 s | 0.0004 s | ~5,000× | | 80,000 | 7.847 s | 0.0007 s | ~11,000× | Fixes #66.
1 parent 7ce2fd5 commit 4bef4c2

1 file changed

Lines changed: 1 addition & 1 deletion

File tree

lib/rss/parser.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -391,7 +391,7 @@ def _ns(ns, prefix)
391391
ns.fetch(prefix, "")
392392
end
393393

394-
CONTENT_PATTERN = /\s*([^=]+)=(["'])([^\2]+?)\2/
394+
CONTENT_PATTERN = /\G\s*([^=]+)=(["'])([^\2]+?)\2/
395395
# Extract the first name="value" pair from content.
396396
# Works with single quotes according to the constant
397397
# CONTENT_PATTERN. Return a Hash.

0 commit comments

Comments
 (0)