Skip to content

Commit

Permalink
[StateTracking] Do in-place compact
Browse files Browse the repository at this point in the history
Signed-off-by: David Crosby <dcrosby@fb.com>
  • Loading branch information
dafyddcrosby committed May 21, 2024
1 parent 3e15017 commit 5214051
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions lib/chef/node/mixin/state_tracking.rb
Original file line number Diff line number Diff line change
Expand Up @@ -37,15 +37,17 @@ def initialize(data = nil, root = self, node = nil, precedence = nil)
def [](*args)
ret = super
key = args.first
next_path = [ __path__, convert_key(key) ].flatten.compact
next_path = [ __path__, convert_key(key) ].flatten
next_path.compact!
copy_state_to(ret, next_path)
end

def []=(*args)
ret = super
key = args.first
value = args.last
next_path = [ __path__, convert_key(key) ].flatten.compact
next_path = [ __path__, convert_key(key) ].flatten
next_path.compact!
send_attribute_changed_event(next_path, value)
copy_state_to(ret, next_path)
end
Expand Down Expand Up @@ -77,7 +79,8 @@ def send_attribute_changed_event(next_path, value)
end

def send_reset_cache(path = nil, key = nil)
next_path = [ path, key ].flatten.compact
next_path = [ path, key ].flatten
next_path.compact!
__root__.reset_cache(next_path.first) if !__root__.nil? && __root__.respond_to?(:reset_cache)
end

Expand Down

0 comments on commit 5214051

Please sign in to comment.