diff --git a/Gemfile b/Gemfile index d695524b..2b39c8f0 100644 --- a/Gemfile +++ b/Gemfile @@ -32,6 +32,7 @@ gem 'test-unit' if RUBY_PLATFORM =~ /cygwin/ || RUBY_VERSION.start_with?("2.2") if ENV['BENCHMARK'] gem 'rbtrace' gem 'stackprof' + gem 'benchmark-ips' end if ENV['PROOF'] diff --git a/benchmark/end-with-vs-regexp b/benchmark/end-with-vs-regexp new file mode 100644 index 00000000..cb849f42 --- /dev/null +++ b/benchmark/end-with-vs-regexp @@ -0,0 +1,13 @@ +require 'benchmark/ips' + +Benchmark.ips do |x| + path_without_ending_slash = '/some/very/very/long/path/to/a/file/i/like' + x.report('no slash regexp') { path_without_ending_slash =~ /\/$/ } + x.report('no slash end_with?') { path_without_ending_slash.end_with?("/") } +end + +Benchmark.ips do |x| + path_with_ending_slash = '/some/very/very/long/path/to/a/file/i/like/' + x.report('slash regexp') { path_with_ending_slash =~ /\/$/ } + x.report('slash end_with?') { path_with_ending_slash.end_with?("/") } +end diff --git a/lib/jekyll/document.rb b/lib/jekyll/document.rb index 048dcdbf..e22e8cf1 100644 --- a/lib/jekyll/document.rb +++ b/lib/jekyll/document.rb @@ -163,7 +163,7 @@ module Jekyll def destination(base_directory) dest = site.in_dest_dir(base_directory) path = site.in_dest_dir(dest, URL.unescape_path(url)) - path = File.join(path, "index.html") if url =~ /\/$/ + path = File.join(path, "index.html") if url.end_with?("/") path end diff --git a/lib/jekyll/page.rb b/lib/jekyll/page.rb index 98f730bf..2db39141 100644 --- a/lib/jekyll/page.rb +++ b/lib/jekyll/page.rb @@ -141,7 +141,7 @@ module Jekyll # Returns the destination file path String. def destination(dest) path = site.in_dest_dir(dest, URL.unescape_path(url)) - path = File.join(path, "index.html") if url =~ /\/$/ + path = File.join(path, "index.html") if url.end_with?("/") path end diff --git a/lib/jekyll/post.rb b/lib/jekyll/post.rb index c74522a9..45b6d0d2 100644 --- a/lib/jekyll/post.rb +++ b/lib/jekyll/post.rb @@ -279,7 +279,7 @@ module Jekyll def destination(dest) # The url needs to be unescaped in order to preserve the correct filename path = site.in_dest_dir(dest, URL.unescape_path(url)) - path = File.join(path, "index.html") if self.url =~ /\/$/ + path = File.join(path, "index.html") if self.url.end_with?("/") path end