Skip to content

Commit

Permalink
MetaschemaNode compute + memoize each descendent node from the root r…
Browse files Browse the repository at this point in the history
…ather than each child of the parent

jsi_schema_base_uri now only comes from the root node's resource_ancestor_uri, which would skip any child schema's #schema_absolute_uri, but is not a problem for any metaschema in use. MetaschemaNode::BootstrapSchema#resource_root_subschema_map is similarly limited.
  • Loading branch information
notEthan committed Aug 2, 2023
1 parent 3888921 commit b8c4b0e
Showing 1 changed file with 16 additions and 4 deletions.
20 changes: 16 additions & 4 deletions lib/jsi/metaschema_node.rb
Expand Up @@ -149,7 +149,7 @@ def initialize(

# see {Base#jsi_child}
def jsi_child(token, as_jsi: )
child_node = jsi_child_node_map[token: token]
child_node = @root_descendent_node_map[ptr: jsi_ptr[token]]

jsi_child_as_jsi(jsi_node_content_child(token), child_node.jsi_schemas, as_jsi) do
child_node
Expand Down Expand Up @@ -194,9 +194,18 @@ def jsi_fingerprint
{class: self.class, jsi_document: jsi_document}.merge(our_initialize_params)
end

protected

attr_reader :root_descendent_node_map

private

def jsi_memomaps_initialize
if jsi_ptr.root?
@root_descendent_node_map = jsi_memomap(key_by: proc { |i| i[:ptr] }, &method(:jsi_root_descendent_node_compute))
else
@root_descendent_node_map = @jsi_root_node.root_descendent_node_map
end
end

# note: does not include jsi_root_node
Expand All @@ -215,10 +224,13 @@ def new_node(**params)
MetaschemaNode.new(jsi_document, jsi_root_node: jsi_root_node, **our_initialize_params, **params)
end

def jsi_child_node_map
jsi_memomap(:subinstance) do |token: |
def jsi_root_descendent_node_compute(ptr: )
#chkbug raise(Bug) unless jsi_ptr.root?
if ptr.root?
self
else
new_node(
jsi_ptr: jsi_ptr[token],
jsi_ptr: ptr,
jsi_schema_base_uri: jsi_resource_ancestor_uri,
)
end
Expand Down

0 comments on commit b8c4b0e

Please sign in to comment.