diff --git a/lib/jekyll/drops/drop.rb b/lib/jekyll/drops/drop.rb index 0586a131..2d31989e 100644 --- a/lib/jekyll/drops/drop.rb +++ b/lib/jekyll/drops/drop.rb @@ -7,6 +7,20 @@ module Jekyll 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 # Get or set whether the drop class is mutable. # 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 # DropMutationException. def []=(key, val) - setter = "#{key}=" + setter = SETTER_KEYS_STASH[key] || "#{key}=" if respond_to?(setter) public_send(setter, val) elsif respond_to?(key.to_s)