Merge pull request #3516 from jekyll/end-with

Use String#end_with?("/") instead of regexp
This commit is contained in:
Parker Moore 2015-02-28 18:55:53 -08:00
commit 50a4b2824b
5 changed files with 17 additions and 3 deletions

View File

@ -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']

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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