diff options
author | Lamont Granquist <lamont@scriptkiddie.org> | 2017-08-28 14:50:04 -0700 |
---|---|---|
committer | GitHub <noreply@github.com> | 2017-08-28 14:50:04 -0700 |
commit | 21bc9dcb780aab71beb79b763214b2276f3634fa (patch) | |
tree | 665774407f77c427c435e88acd3985cdb1856900 | |
parent | f4d91ff42eaa6bb939518f35751f17cab07ec3ff (diff) | |
parent | a556a6d04efdba1d4e5b94f41d6118e179c341df (diff) | |
download | chef-21bc9dcb780aab71beb79b763214b2276f3634fa.tar.gz |
Merge pull request #6355 from chef/lcg/immutablize-speedup
speed up immutabilization
-rw-r--r-- | lib/chef/node/immutable_collections.rb | 2 | ||||
-rw-r--r-- | spec/unit/node/immutable_collections_spec.rb | 16 |
2 files changed, 13 insertions, 5 deletions
diff --git a/lib/chef/node/immutable_collections.rb b/lib/chef/node/immutable_collections.rb index be9285a755..5ac560b4d5 100644 --- a/lib/chef/node/immutable_collections.rb +++ b/lib/chef/node/immutable_collections.rb @@ -115,7 +115,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 520bc1ba42..2d3392041c 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 @@ -168,7 +176,7 @@ describe Chef::Node::ImmutableArray do before do @immutable_array = Chef::Node::ImmutableArray.new(%w{foo bar baz} + Array(1..3) + [nil, true, false, [ "el", 0, nil ] ]) - immutable_mash = Chef::Node::ImmutableMash.new({ :m => "m" }) + immutable_mash = Chef::Node::ImmutableMash.new({ "m" => "m" }) @immutable_nested_array = Chef::Node::ImmutableArray.new(["level1", @immutable_array, immutable_mash]) end |