Skip to content

Commit 8d8cd36

Browse files
abrissegkellogg
authored andcommitted
fix(performance): comment all log_debug
1 parent 742eecb commit 8d8cd36

File tree

8 files changed

+103
-103
lines changed

8 files changed

+103
-103
lines changed

lib/json/ld/api.rb

+8-8
Original file line numberDiff line numberDiff line change
@@ -236,7 +236,7 @@ def self.compact(input, context, expanded: false, serializer: nil, **options)
236236
end
237237

238238
API.new(expanded_input, context, no_default_base: true, **options) do
239-
log_debug(".compact") {"expanded input: #{expanded_input.to_json(JSON_STATE) rescue 'malformed json'}"}
239+
# log_debug(".compact") {"expanded input: #{expanded_input.to_json(JSON_STATE) rescue 'malformed json'}"}
240240
result = compact(value)
241241

242242
# xxx) Add the given context to the output
@@ -290,7 +290,7 @@ def self.flatten(input, context, expanded: false, serializer: nil, **options)
290290

291291
# Initialize input using
292292
API.new(expanded_input, context, no_default_base: true, **options) do
293-
log_debug(".flatten") {"expanded input: #{value.to_json(JSON_STATE) rescue 'malformed json'}"}
293+
# log_debug(".flatten") {"expanded input: #{value.to_json(JSON_STATE) rescue 'malformed json'}"}
294294

295295
# Rename blank nodes recusively. Note that this does not create new blank node identifiers where none exist, which is performed in the node map generation algorithm.
296296
@value = rename_bnodes(@value) if @options[:rename_bnodes]
@@ -411,8 +411,8 @@ def self.frame(input, frame, expanded: false, serializer: nil, **options)
411411

412412
# Initialize input using frame as context
413413
API.new(expanded_input, frame['@context'], no_default_base: true, **options) do
414-
log_debug(".frame") {"expanded input: #{expanded_input.to_json(JSON_STATE) rescue 'malformed json'}"}
415-
log_debug(".frame") {"expanded frame: #{expanded_frame.to_json(JSON_STATE) rescue 'malformed json'}"}
414+
# log_debug(".frame") {"expanded input: #{expanded_input.to_json(JSON_STATE) rescue 'malformed json'}"}
415+
# log_debug(".frame") {"expanded frame: #{expanded_frame.to_json(JSON_STATE) rescue 'malformed json'}"}
416416

417417
if %w(@first @last).include?(options[:embed]) && context.processingMode('json-ld-1.1')
418418
raise JSON::LD::JsonLdError::InvalidEmbedValue, "#{options[:embed]} is not a valid value of @embed in 1.1 mode" if @options[:validate]
@@ -459,7 +459,7 @@ def self.frame(input, frame, expanded: false, serializer: nil, **options)
459459

460460
# Replace values with `@preserve` with the content of its entry.
461461
result = cleanup_preserve(result)
462-
log_debug(".frame") {"expanded result: #{result.to_json(JSON_STATE) rescue 'malformed json'}"}
462+
# log_debug(".frame") {"expanded result: #{result.to_json(JSON_STATE) rescue 'malformed json'}"}
463463

464464
# Compact result
465465
compacted = compact(result)
@@ -478,7 +478,7 @@ def self.frame(input, frame, expanded: false, serializer: nil, **options)
478478
# Only add context if one was provided
479479
result = context.serialize(provided_context: frame).merge(result) if frame['@context']
480480

481-
log_debug(".frame") {"after compact: #{result.to_json(JSON_STATE) rescue 'malformed json'}"}
481+
# log_debug(".frame") {"after compact: #{result.to_json(JSON_STATE) rescue 'malformed json'}"}
482482
result
483483
end
484484

@@ -519,7 +519,7 @@ def self.toRdf(input, expanded: false, **options, &block)
519519
API.new(flattened_input, nil, **options) do
520520
# 1) Perform the Expansion Algorithm on the JSON-LD input.
521521
# This removes any existing context to allow the given context to be cleanly applied.
522-
log_debug(".toRdf") {"flattened input: #{flattened_input.to_json(JSON_STATE) rescue 'malformed json'}"}
522+
# log_debug(".toRdf") {"flattened input: #{flattened_input.to_json(JSON_STATE) rescue 'malformed json'}"}
523523

524524
# Recurse through input
525525
flattened_input.each do |node|
@@ -528,7 +528,7 @@ def self.toRdf(input, expanded: false, **options, &block)
528528

529529
# Drop invalid statements (other than IRIs)
530530
unless statement.valid_extended?
531-
log_debug(".toRdf") {"drop invalid statement: #{statement.to_nquads}"}
531+
# log_debug(".toRdf") {"drop invalid statement: #{statement.to_nquads}"}
532532
next
533533
end
534534

lib/json/ld/compact.rb

+16-16
Original file line numberDiff line numberDiff line change
@@ -21,14 +21,14 @@ def compact(element,
2121
base: nil,
2222
property: nil,
2323
log_depth: nil)
24-
log_debug("compact", depth: log_depth.to_i) {"element: #{element.inspect}, ec: #{context.inspect}"}
24+
# log_debug("compact", depth: log_depth.to_i) {"element: #{element.inspect}, ec: #{context.inspect}"}
2525

2626
# If the term definition for active property itself contains a context, use that for compacting values.
2727
input_context = self.context
2828

2929
case element
3030
when Array
31-
#log_debug("") {"Array #{element.inspect}"}
31+
# log_debug("") {"Array #{element.inspect}"}
3232
result = element.map do |item|
3333
compact(item, base: base, property: property, log_depth: log_depth.to_i + 1)
3434
end.compact
@@ -38,10 +38,10 @@ def compact(element,
3838
# member; otherwise the compacted value is element
3939
if result.length == 1 &&
4040
!context.as_array?(property) && @options[:compactArrays]
41-
log_debug("=> extract single element", depth: log_depth.to_i) {result.first.inspect}
41+
# log_debug("=> extract single element", depth: log_depth.to_i) {result.first.inspect}
4242
result.first
4343
else
44-
log_debug("=> array result", depth: log_depth.to_i) {result.inspect}
44+
# log_debug("=> array result", depth: log_depth.to_i) {result.inspect}
4545
result
4646
end
4747
when Hash
@@ -52,7 +52,7 @@ def compact(element,
5252

5353
# Revert any previously type-scoped (non-preserved) context
5454
if context.previous_context && !element.key?('@value') && element.keys != %w(@id)
55-
log_debug("revert ec", depth: log_depth.to_i) {"previous context: #{context.previous_context.inspect}"}
55+
# log_debug("revert ec", depth: log_depth.to_i) {"previous context: #{context.previous_context.inspect}"}
5656
self.context = context.previous_context
5757
end
5858

@@ -61,13 +61,13 @@ def compact(element,
6161
if td && !td.context.nil?
6262
self.context = context.parse(td.context,
6363
override_protected: true)
64-
log_debug("prop-scoped", depth: log_depth.to_i) {"context: #{self.context.inspect}"}
64+
# log_debug("prop-scoped", depth: log_depth.to_i) {"context: #{self.context.inspect}"}
6565
end
6666

6767
if (element.key?('@id') || element.key?('@value')) && !element.key?('@annotation')
6868
result = context.compact_value(property, element, base: @options[:base])
6969
if !result.is_a?(Hash) || context.coerce(property) == '@json'
70-
log_debug("", depth: log_depth.to_i) {"=> scalar result: #{result.inspect}"}
70+
# log_debug("", depth: log_depth.to_i) {"=> scalar result: #{result.inspect}"}
7171
return result
7272
end
7373
end
@@ -90,12 +90,12 @@ def compact(element,
9090
each do |term|
9191
term_context = input_context.term_definitions[term].context if input_context.term_definitions[term]
9292
self.context = context.parse(term_context, propagate: false) unless term_context.nil?
93-
log_debug("type-scoped", depth: log_depth.to_i) {"context: #{self.context.inspect}"}
93+
# log_debug("type-scoped", depth: log_depth.to_i) {"context: #{self.context.inspect}"}
9494
end
9595

9696
element.keys.opt_sort(ordered: @options[:ordered]).each do |expanded_property|
9797
expanded_value = element[expanded_property]
98-
log_debug("", depth: log_depth.to_i) {"#{expanded_property}: #{expanded_value.inspect}"}
98+
# log_debug("", depth: log_depth.to_i) {"#{expanded_property}: #{expanded_value.inspect}"}
9999

100100
if expanded_property == '@id'
101101
compacted_value = as_array(expanded_value).map do |expanded_id|
@@ -134,7 +134,7 @@ def compact(element,
134134
compacted_value = compact(expanded_value, base: base,
135135
property: '@reverse',
136136
log_depth: log_depth.to_i + 1)
137-
log_debug("@reverse", depth: log_depth.to_i) {"compacted_value: #{compacted_value.inspect}"}
137+
# log_debug("@reverse", depth: log_depth.to_i) {"compacted_value: #{compacted_value.inspect}"}
138138
# handle double-reversed properties
139139
compacted_value.each do |prop, value|
140140
if context.reverse?(prop)
@@ -146,7 +146,7 @@ def compact(element,
146146

147147
unless compacted_value.empty?
148148
al = context.compact_iri('@reverse', vocab: true)
149-
log_debug("", depth: log_depth.to_i) {"remainder: #{al} => #{compacted_value.inspect}"}
149+
# log_debug("", depth: log_depth.to_i) {"remainder: #{al} => #{compacted_value.inspect}"}
150150
result[al] = compacted_value
151151
end
152152
next
@@ -157,7 +157,7 @@ def compact(element,
157157
compacted_value = compact(expanded_value, base: base,
158158
property: property,
159159
log_depth: log_depth.to_i + 1)
160-
log_debug("@preserve", depth: log_depth.to_i) {"compacted_value: #{compacted_value.inspect}"}
160+
# log_debug("@preserve", depth: log_depth.to_i) {"compacted_value: #{compacted_value.inspect}"}
161161

162162
unless compacted_value.is_a?(Array) && compacted_value.empty?
163163
result['@preserve'] = compacted_value
@@ -166,14 +166,14 @@ def compact(element,
166166
end
167167

168168
if expanded_property == '@index' && context.container(property).include?('@index')
169-
log_debug("@index", depth: log_depth.to_i) {"drop @index"}
169+
# log_debug("@index", depth: log_depth.to_i) {"drop @index"}
170170
next
171171
end
172172

173173
# Otherwise, if expanded property is @direction, @index, @value, or @language:
174174
if EXPANDED_PROPERTY_DIRECTION_INDEX_LANGUAGE_VALUE.include?(expanded_property)
175175
al = context.compact_iri(expanded_property, vocab: true)
176-
log_debug(expanded_property, depth: log_depth.to_i) {"#{al} => #{expanded_value.inspect}"}
176+
# log_debug(expanded_property, depth: log_depth.to_i) {"#{al} => #{expanded_value.inspect}"}
177177
result[al] = expanded_value
178178
next
179179
end
@@ -223,7 +223,7 @@ def compact(element,
223223
compacted_item = compact(value, base: base,
224224
property: item_active_property,
225225
log_depth: log_depth.to_i + 1)
226-
log_debug("", depth: log_depth.to_i) {" => compacted key: #{item_active_property.inspect} for #{compacted_item.inspect}"}
226+
# log_debug("", depth: log_depth.to_i) {" => compacted key: #{item_active_property.inspect} for #{compacted_item.inspect}"}
227227

228228
# handle @list
229229
if list?(expanded_item)
@@ -345,7 +345,7 @@ def compact(element,
345345
result
346346
else
347347
# For other types, the compacted value is the element value
348-
log_debug("compact", depth: log_depth.to_i) {element.class.to_s}
348+
# log_debug("compact", depth: log_depth.to_i) {element.class.to_s}
349349
element
350350
end
351351

0 commit comments

Comments
 (0)