Reduce string allocations with better alternatives (#7643)
Merge pull request 7643
This commit is contained in:
parent
1658a1596e
commit
cbfdeaefcd
|
@ -75,12 +75,14 @@ module Jekyll
|
|||
def entries
|
||||
return [] unless exists?
|
||||
|
||||
@entries ||=
|
||||
@entries ||= begin
|
||||
collection_dir_slash = "#{collection_dir}/"
|
||||
Utils.safe_glob(collection_dir, ["**", "*"], File::FNM_DOTMATCH).map do |entry|
|
||||
entry["#{collection_dir}/"] = ""
|
||||
entry[collection_dir_slash] = ""
|
||||
entry
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
# Filtered version of the entries in this collection.
|
||||
# See `Jekyll::EntryFilter#filter` for more information.
|
||||
|
|
|
@ -65,8 +65,9 @@ module Jekyll
|
|||
# and the key matches a method in which case it raises a
|
||||
# DropMutationException.
|
||||
def []=(key, val)
|
||||
if respond_to?("#{key}=")
|
||||
public_send("#{key}=", val)
|
||||
setter = "#{key}="
|
||||
if respond_to?(setter)
|
||||
public_send(setter, val)
|
||||
elsif respond_to?(key.to_s)
|
||||
if self.class.mutable?
|
||||
mutations[key] = val
|
||||
|
|
|
@ -91,7 +91,7 @@ module Jekyll
|
|||
# Returns true if path matches against any glob pattern.
|
||||
# --
|
||||
def glob_include?(enum, entry)
|
||||
entry_path = Pathutil.new(site.in_source_dir).join(entry)
|
||||
entry_path = source_path.join(entry)
|
||||
enum.any? do |exp|
|
||||
# Users who send a Regexp knows what they want to
|
||||
# exclude, so let them send a Regexp to exclude files,
|
||||
|
@ -102,7 +102,7 @@ module Jekyll
|
|||
entry_path =~ exp
|
||||
|
||||
else
|
||||
item = Pathutil.new(site.in_source_dir).join(exp)
|
||||
item = source_path.join(exp)
|
||||
|
||||
# If it's a directory they want to exclude, AKA
|
||||
# ends with a "/" then we will go on to check and
|
||||
|
@ -123,5 +123,11 @@ module Jekyll
|
|||
end
|
||||
end
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def source_path
|
||||
@source_path ||= Pathutil.new(site.in_source_dir)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -111,7 +111,7 @@ module Jekyll
|
|||
if scope["path"].to_s.include?("*")
|
||||
glob_scope(sanitized_path, rel_scope_path)
|
||||
else
|
||||
path_is_subpath?(sanitized_path, strip_collections_dir(rel_scope_path))
|
||||
path_is_subpath?(sanitized_path, strip_collections_dir(scope["path"]))
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -120,7 +120,7 @@ module Jekyll
|
|||
abs_scope_path = site_source.join(rel_scope_path).to_s
|
||||
|
||||
glob_cache(abs_scope_path).each do |scope_path|
|
||||
scope_path = Pathname.new(scope_path).relative_path_from(site_source)
|
||||
scope_path = Pathname.new(scope_path).relative_path_from(site_source).to_s
|
||||
scope_path = strip_collections_dir(scope_path)
|
||||
Jekyll.logger.debug "Globbed Scope Path:", scope_path
|
||||
return true if path_is_subpath?(sanitized_path, scope_path)
|
||||
|
@ -143,7 +143,7 @@ module Jekyll
|
|||
|
||||
def strip_collections_dir(path)
|
||||
collections_dir = @site.config["collections_dir"]
|
||||
slashed_coll_dir = "#{collections_dir}/"
|
||||
slashed_coll_dir = collections_dir.empty? ? "/" : "#{collections_dir}/"
|
||||
return path if collections_dir.empty? || !path.to_s.start_with?(slashed_coll_dir)
|
||||
|
||||
path.sub(slashed_coll_dir, "")
|
||||
|
|
|
@ -72,7 +72,7 @@ module Jekyll
|
|||
def proc_version
|
||||
@proc_version ||=
|
||||
begin
|
||||
Pathutil.new("/proc/version").read
|
||||
File.read("/proc/version")
|
||||
rescue Errno::ENOENT, Errno::EACCES
|
||||
nil
|
||||
end
|
||||
|
|
Loading…
Reference in New Issue