Skip to content

Commit 178afc2

Browse files
committed
Only allocate result hash once in JSON::LD::Frame#count_blank_node_identifiers.
1 parent 1a33a60 commit 178afc2

File tree

1 file changed

+18
-13
lines changed

1 file changed

+18
-13
lines changed

lib/json/ld/frame.rb

Lines changed: 18 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -191,21 +191,26 @@ def frame(state, subjects, frame, **options)
191191
##
192192
# Recursively find and count blankNode identifiers.
193193
# @return [Hash{String => Integer}]
194-
def count_blank_node_identifiers(input, results = {})
194+
def count_blank_node_identifiers(input)
195+
{}.tap do |results|
196+
count_blank_node_identifiers_internal(input, results)
197+
end
198+
end
199+
200+
def count_blank_node_identifiers_internal(input, results)
195201
case input
196-
when Array
197-
input.map {|o| count_blank_node_identifiers(o, results)}
198-
when Hash
199-
input.each do |k, v|
200-
count_blank_node_identifiers(v, results)
201-
end
202-
when String
203-
if input.start_with?('_:')
204-
results[input] ||= 0
205-
results[input] += 1
206-
end
202+
when Array
203+
input.each {|o| count_blank_node_identifiers_internal(o, results)}
204+
when Hash
205+
input.each do |k, v|
206+
count_blank_node_identifiers_internal(v, results)
207+
end
208+
when String
209+
if input.start_with?('_:')
210+
results[input] ||= 0
211+
results[input] += 1
212+
end
207213
end
208-
results
209214
end
210215

211216
##

0 commit comments

Comments
 (0)