Skip to content

Commit

Permalink
Merge pull request #3516 from jekyll/end-with
Browse files Browse the repository at this point in the history
Use String#end_with?("/") instead of regexp
  • Loading branch information
parkr committed Mar 1, 2015
2 parents 8e87e9e + 6c073ec commit 50a4b28
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 3 deletions.
1 change: 1 addition & 0 deletions Gemfile
Expand Up @@ -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']
Expand Down
13 changes: 13 additions & 0 deletions 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
2 changes: 1 addition & 1 deletion lib/jekyll/document.rb
Expand Up @@ -163,7 +163,7 @@ def url
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

Expand Down
2 changes: 1 addition & 1 deletion lib/jekyll/page.rb
Expand Up @@ -141,7 +141,7 @@ def relative_path
# 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

Expand Down
2 changes: 1 addition & 1 deletion lib/jekyll/post.rb
Expand Up @@ -279,7 +279,7 @@ def render(layouts, site_payload)
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

Expand Down

0 comments on commit 50a4b28

Please sign in to comment.