summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLamont Granquist <lamont@scriptkiddie.org>2017-08-28 13:06:51 -0700
committerLamont Granquist <lamont@scriptkiddie.org>2017-08-28 14:52:22 -0700
commitc3e0f4b932b26d98047ea0372241417ac044bfcd (patch)
treed7f4298dea4ba450ded5efc3bb397007a55e976d
parent4ba94438788706ceae12706c539d5cda101fb89b (diff)
downloadchef-c3e0f4b932b26d98047ea0372241417ac044bfcd.tar.gz
speed up immutabilization
since we only inject Mash/VividMashes do not convert Signed-off-by: Lamont Granquist <lamont@scriptkiddie.org>
-rw-r--r--lib/chef/node/immutable_collections.rb2
-rw-r--r--spec/unit/node/immutable_collections_spec.rb14
2 files changed, 12 insertions, 4 deletions
diff --git a/lib/chef/node/immutable_collections.rb b/lib/chef/node/immutable_collections.rb
index dad712e078..3b7d47b687 100644
--- a/lib/chef/node/immutable_collections.rb
+++ b/lib/chef/node/immutable_collections.rb
@@ -110,7 +110,7 @@ class Chef
include Immutablize
include CommonAPI
- alias :internal_set :[]=
+ alias :internal_set :regular_writer
private :internal_set
def initialize(mash_data = {})
diff --git a/spec/unit/node/immutable_collections_spec.rb b/spec/unit/node/immutable_collections_spec.rb
index 81dd771df3..b7b8bcdc9e 100644
--- a/spec/unit/node/immutable_collections_spec.rb
+++ b/spec/unit/node/immutable_collections_spec.rb
@@ -21,10 +21,10 @@ require "chef/node/immutable_collections"
describe Chef::Node::ImmutableMash do
before do
- @data_in = { :top => { :second_level => "some value" },
+ @data_in = { "top" => { "second_level" => "some value" },
"top_level_2" => %w{array of values},
- :top_level_3 => [{ :hash_array => 1, :hash_array_b => 2 }],
- :top_level_4 => { :level2 => { :key => "value" } },
+ "top_level_3" => [{ "hash_array" => 1, "hash_array_b" => 2 }],
+ "top_level_4" => { "level2" => { "key" => "value" } },
}
@immutable_mash = Chef::Node::ImmutableMash.new(@data_in)
end
@@ -54,6 +54,14 @@ describe Chef::Node::ImmutableMash do
expect(@immutable_mash[:top_level_4][:level2]).to be_a(Chef::Node::ImmutableMash)
end
+ # we only ever absorb VividMashes from other precedence levels, which already have
+ # been coerced to only have string keys, so we do not need to do that work twice (performance).
+ it "does not call convert_value like Mash/VividMash" do
+ @mash = Chef::Node::ImmutableMash.new({ test: "foo", "test2" => "bar" })
+ expect(@mash[:test]).to eql("foo")
+ expect(@mash["test2"]).to eql("bar")
+ end
+
describe "to_hash" do
before do
@copy = @immutable_mash.to_hash