Skip to content

Commit 84beced

Browse files
committed
Reduce duplicated objects in context merge.
1 parent a7e7927 commit 84beced

File tree

1 file changed

+9
-8
lines changed

1 file changed

+9
-8
lines changed

lib/json/ld/context.rb

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -638,12 +638,12 @@ def parse(local_context,
638638
#log_debug("parse") {"Failed to retrieve @context from remote document at #{context_no_base.context_base.inspect}: #{e.message}"}
639639
raise JsonLdError::LoadingRemoteContextFailed, "#{context}: #{e.message}", e.backtrace
640640
end
641-
end.dup()
641+
end
642642

643643
# Merge loaded context noting protected term overriding
644644
context = result.merge(cached_context, override_protected: override_protected)
645645

646-
context.previous_context = result unless propagate
646+
context.previous_context = self unless propagate
647647
result = context
648648
#log_debug("parse") {"=> provided_context: #{context.inspect}"}
649649
when Hash
@@ -722,12 +722,13 @@ def parse(local_context,
722722
# @param [Boolean]
723723
# @return [Context]
724724
def merge(context, override_protected: false)
725-
ctx = self.dup
726-
ctx.context_base = context.context_base if context.context_base
727-
ctx.default_language = context.default_language if context.default_language
728-
ctx.default_direction = context.default_direction if context.default_direction
729-
ctx.vocab = context.vocab if context.vocab
730-
ctx.base = context.base if context.base
725+
ctx = Context.new(term_definitions: self.term_definitions.dup(), standard_prefixes: options[:standard_prefixes])
726+
ctx.context_base = context.context_base || self.context_base
727+
ctx.default_language = context.default_language || self.default_language
728+
ctx.default_direction = context.default_direction || self.default_direction
729+
ctx.vocab = context.vocab || self.vocab
730+
ctx.base = context.base || self.base
731+
ctx.provided_context = self.provided_context
731732
if !override_protected
732733
ctx.term_definitions.each do |term, definition|
733734
next unless definition.protected? && (other = context.term_definitions[term])

0 commit comments

Comments
 (0)