Skip to content

Commit 59c1d64

Browse files
committed
Use String#include? over String#=~
Warming up -------------------------------------- no body include? 114.533k i/100ms no body regexp 40.573k i/100ms Calculating ------------------------------------- no body include? 2.443M (± 3.6%) i/s - 12.255M no body regexp 507.675k (± 2.3%) i/s - 2.556M Comparison: no body include?: 2442987.7 i/s no body regexp: 507675.5 i/s - 4.81x slower Warming up -------------------------------------- with body include? 114.182k i/100ms with body regexp 40.746k i/100ms Calculating ------------------------------------- with body include? 2.334M (± 7.4%) i/s - 11.647M with body regexp 450.995k (± 5.8%) i/s - 2.282M Comparison: with body include?: 2334117.9 i/s with body regexp: 450995.3 i/s - 5.18x slower Code: jekyll/jekyll@c28a17d
1 parent 085bf95 commit 59c1d64

File tree

1 file changed

+3
-1
lines changed

1 file changed

+3
-1
lines changed

lib/jekyll-mentions.rb

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,16 @@
44
module Jekyll
55
class Mentions
66
GITHUB_DOT_COM = "https://github.com".freeze
7+
BODY_START_TAG = "<body".freeze
8+
79

810
InvalidJekyllMentionConfig = Class.new(Jekyll::Errors::FatalException)
911

1012
class << self
1113
def mentionify(doc)
1214
return unless doc.output.include?("@")
1315
src = mention_base(doc.site.config)
14-
if doc.output =~ /<\s*body/
16+
if doc.output.include? BODY_START_TAG
1517
parsed_doc = Nokogiri::HTML::Document.parse(doc.output)
1618
body = parsed_doc.at_css('body')
1719
body.children = filter_with_mention(src).call(body.inner_html)[:output].to_s

0 commit comments

Comments
 (0)