Stash frequently used Drop setter keys for reuse (#8394)

Merge pull request 8394
This commit is contained in:
Ashwin Maroli 2020-10-11 14:45:46 +05:30 committed by GitHub
parent e0221ed3a8
commit 5dc43a88de
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 15 additions and 1 deletions

View File

@ -7,6 +7,20 @@ module Jekyll
NON_CONTENT_METHODS = [:fallback_data, :collapse_document].freeze NON_CONTENT_METHODS = [:fallback_data, :collapse_document].freeze
# A private stash to avoid repeatedly generating the setter method name string for
# a call to `Drops::Drop#[]=`.
# The keys of the stash below have a very high probability of being called upon during
# the course of various `Jekyll::Renderer#run` calls.
SETTER_KEYS_STASH = {
"content" => "content=",
"layout" => "layout=",
"page" => "page=",
"paginator" => "paginator=",
"highlighter_prefix" => "highlighter_prefix=",
"highlighter_suffix" => "highlighter_suffix=",
}.freeze
private_constant :SETTER_KEYS_STASH
class << self class << self
# Get or set whether the drop class is mutable. # Get or set whether the drop class is mutable.
# Mutability determines whether or not pre-defined fields may be # Mutability determines whether or not pre-defined fields may be
@ -119,7 +133,7 @@ module Jekyll
# and the key matches a method in which case it raises a # and the key matches a method in which case it raises a
# DropMutationException. # DropMutationException.
def []=(key, val) def []=(key, val)
setter = "#{key}=" setter = SETTER_KEYS_STASH[key] || "#{key}="
if respond_to?(setter) if respond_to?(setter)
public_send(setter, val) public_send(setter, val)
elsif respond_to?(key.to_s) elsif respond_to?(key.to_s)