lutaml-model 0.8.154 → 0.8.155

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 6be6e9b6e0d81dbc991b1d7cda6e6a81101108775c4638f09388bd508a8e2f38
4
- data.tar.gz: 4d3807bd5c51e9c5d2554bbf72f875eb2f055d214fc6efcaa670a161cf7de21e
3
+ metadata.gz: 4f049fe423c9adf8973b1c7c91fd9a5ab511a6016028eb9a039e16c3abfae6cd
4
+ data.tar.gz: 0d828bc248dfa95d49dd706e105c9282b8595b5ce5c8e019e5b707ac8b8d01b8
5
5
  SHA512:
6
- metadata.gz: a35214810fd059595ce1cd8ed7d8e7cbeb4d8286da37f9a3a55dfcdd923147e9d8a8b003f6a216c2237dd2cdc21e238194a5a1ac7c9b056f34e3cfae9e8b7549
7
- data.tar.gz: 025c3a00a72de6a7e89a102d7b4ccfbd52f08d357f5a33a5771055330acb2eb93cba406f53e51e6cd05891171418f488775d9128d07f7752be881a99bb729a99
6
+ metadata.gz: '093c0c8b6c3e68f63199039d78b53982dfaef7c1ac21215692e83218944921a5ebac18f1a414d534ef6658516122ff4fc862155921b41c8bc0bc0a781034ba48'
7
+ data.tar.gz: 03fa63223f5a20af8c33d9e556de6b6ee381496180c441cb18ec0505f5a5ae759488d1db0b3316c5a3fd01bc18dd4aee3c0c55be8b4dccc3e7eb3ff5a21f3b11
@@ -62,8 +62,16 @@ jobs:
62
62
  # until it migrates to the moxml-ts wasm binding. The gemspec
63
63
  # admits both lines (>= 0.5.139, < 0.7), so this lockfile-local
64
64
  # pin selects the Opal-compatible one without restricting
65
- # CRuby consumers.
66
- run: bundle update moxml --version '~> 0.5.139'
65
+ # CRuby consumers. The constraint rides a workspace-local
66
+ # Gemfile append — `bundle update` has no --version switch, and
67
+ # the repo's Gemfile/gemspec must stay dual-line for CRuby.
68
+ run: |
69
+ cat >> Gemfile <<'EOF'
70
+
71
+ # CI-local pin (opal.yml): the Opal boot needs moxml 0.5.x.
72
+ gem "moxml", "~> 0.5.139"
73
+ EOF
74
+ bundle update moxml
67
75
 
68
76
  - name: Run Opal tests
69
77
  run: bundle exec rake spec:opal
@@ -74,6 +74,11 @@ module Lutaml
74
74
  @custom_methods = custom_methods || {}
75
75
  @alias_names = alias_names
76
76
  @options = options
77
+ # Static per rule; computed here because compiled rules are frozen.
78
+ rule_name = attribute_name.to_s
79
+ @custom_method_only = (rule_name.start_with?("__") &&
80
+ rule_name.end_with?("__")) ||
81
+ (!@custom_methods.empty? && attribute_type.nil?)
77
82
  freeze
78
83
  end
79
84
 
@@ -208,13 +213,10 @@ module Lutaml
208
213
  # @param args [Array] Arguments (ignored for options)
209
214
  # @param block [Proc] Block (ignored for options)
210
215
  # @return [Object] The option value or nil
211
- # Static per rule (see MappingRule#custom_method_only?). Compiled
212
- # rules are frozen, so the answer is recomputed with a single
213
- # to_s instead of the historical two.
216
+ # Static per rule, precomputed at construction (compiled rules are
217
+ # frozen, so it cannot be memoized afterwards).
214
218
  def custom_method_only?
215
- name = attribute_name.to_s
216
- (name.start_with?("__") && name.end_with?("__")) ||
217
- (!custom_methods.empty? && attribute_type.nil?)
219
+ @custom_method_only
218
220
  end
219
221
 
220
222
  def method_missing(method_name, *args, &block)
@@ -2,6 +2,6 @@
2
2
 
3
3
  module Lutaml
4
4
  module Model
5
- VERSION = "0.8.154"
5
+ VERSION = "0.8.155"
6
6
  end
7
7
  end
@@ -41,23 +41,40 @@ reason: nil)
41
41
  freeze
42
42
  end
43
43
 
44
+ # Interned frozen decisions, nested reason → namespace class →
45
+ # prefix, so the hot per-element factory calls reuse one frozen
46
+ # instance per distinct combination instead of rebuilding one.
47
+ @interned = {}
48
+
49
+ class << self
50
+ def interned
51
+ @interned
52
+ end
53
+ end
54
+
44
55
  # Convenience factory for prefix format decisions
45
56
  def self.prefix(prefix:, namespace_class:, reason:)
46
- new(format: :prefix, prefix: prefix,
47
- namespace_class: namespace_class, reason: reason)
57
+ by_class = (interned[reason] ||= {})[namespace_class] ||= {}
58
+ by_class[prefix] ||= new(format: :prefix, prefix: prefix,
59
+ namespace_class: namespace_class,
60
+ reason: reason)
48
61
  end
49
62
 
50
63
  # Convenience factory for default format decisions
51
64
  def self.default(namespace_class:, reason:)
52
- new(format: :default, prefix: nil,
53
- namespace_class: namespace_class, reason: reason)
65
+ by_class = (interned[reason] ||= {})[namespace_class] ||= {}
66
+ by_class[nil] ||= new(format: :default, prefix: nil,
67
+ namespace_class: namespace_class,
68
+ reason: reason)
54
69
  end
55
70
 
56
71
  # Convenience factory for blank namespace decisions
57
72
  # Blank namespace means no xmlns attribute (element not in any namespace)
58
73
  def self.blank(namespace_class:, reason:)
59
- new(format: :blank, prefix: nil,
60
- namespace_class: namespace_class, reason: reason)
74
+ by_class = (interned[reason] ||= {})[namespace_class] ||= {}
75
+ by_class[nil] ||= new(format: :blank, prefix: nil,
76
+ namespace_class: namespace_class,
77
+ reason: reason)
61
78
  end
62
79
 
63
80
  # Check if this decision uses prefix format
@@ -222,11 +222,18 @@ module Lutaml
222
222
  def ambiguous_local_spellings?(node, local_name)
223
223
  return false unless node.respond_to?(:attributes)
224
224
 
225
+ # Allocation-free: the local part is compared as a suffix of
226
+ # the raw name instead of splitting out a fresh substring.
227
+ llen = local_name.length
225
228
  seen = false
226
229
  node.attributes.each_value do |attr|
227
230
  name = attr.name.to_s
228
- name = name.split(":").last if name.include?(":")
229
- next unless name == local_name
231
+ if (colon = name.rindex(":"))
232
+ next unless name.length - colon - 1 == llen &&
233
+ name.end_with?(local_name)
234
+ elsif name != local_name
235
+ next
236
+ end
230
237
 
231
238
  return true if seen
232
239
 
@@ -737,8 +737,15 @@ _effective_register)
737
737
  # prefix + local suffix so prefixed attributes (whose
738
738
  # namespaced_name is "prefix:local", never "uri:local") still
739
739
  # match, and unprefixed_name is not called per attribute
740
- # (it splits prefixed names and allocates).
741
- local_name = rule_name[(last_colon_index + 1)..]
740
+ # (it splits prefixed names and allocates). The split reuses
741
+ # match_attribute_by_local_name's per-spelling memo.
742
+ parts = NAMESPACED_NAME_PARTS[rule_name]
743
+ unless parts
744
+ parts = [rule_name[(last_colon_index + 1)..],
745
+ rule_name[0...last_colon_index]]
746
+ NAMESPACED_NAME_PARTS[rule_name] = parts
747
+ end
748
+ local_name = parts[0]
742
749
  if session
743
750
  candidates = session.element_local_attribute_index(doc.root)[local_name]
744
751
  # No candidate carries this local name: nothing in the
@@ -533,7 +533,9 @@ module Lutaml
533
533
 
534
534
  if attributes.any?
535
535
  # ✅ INSTANCE-AWARE FIX: Build set of actual attribute names
536
- actual_attr_names = Set.new(element.attributes.map(&:name))
536
+ # (single pass — no intermediate map Array per element)
537
+ actual_attr_names = Set.new
538
+ element.attributes.each { |attr| actual_attr_names << attr.name }
537
539
 
538
540
  # Collect Type refs for XML attributes (instance-aware)
539
541
  mapping.attributes.each do |attr_rule|
@@ -554,7 +556,10 @@ module Lutaml
554
556
 
555
557
  # Collect Type refs for XML elements (only for present elements)
556
558
  # Get actual element names from XmlElement children
557
- actual_elem_names = Set.new(element.children.grep(Lutaml::Xml::DataModel::XmlElement).map(&:name))
559
+ actual_elem_names = Set.new
560
+ element.children.each do |child|
561
+ actual_elem_names << child.name if child.is_a?(Lutaml::Xml::DataModel::XmlElement)
562
+ end
558
563
  mapping.elements.each do |elem_rule|
559
564
  # Skip if element not present in XmlElement tree
560
565
  next unless actual_elem_names.include?(elem_rule.name.to_s)
@@ -584,14 +589,17 @@ module Lutaml
584
589
  end
585
590
 
586
591
  # Recursively collect from children in XmlElement tree
592
+ rules_by_name = nil
587
593
  element.children.each do |child|
588
594
  if child.is_a?(Lutaml::Xml::DataModel::XmlElement)
589
595
  # ✅ FIX: Match child XmlElement to its corresponding element rule
590
- # to get the correct child mapping
591
- child_name = child.name
592
- matching_rule = mapping.elements.find do |rule|
593
- rule.name.to_s == child_name
596
+ # to get the correct child mapping. The name→rule index is built
597
+ # once per collection instead of a linear find per child.
598
+ rules_by_name ||= mapping.elements.each_with_object({}) do |rule, index|
599
+ index[rule.name.to_s] ||= rule
594
600
  end
601
+ child_name = child.name
602
+ matching_rule = rules_by_name[child_name]
595
603
 
596
604
  if matching_rule && attributes.any?
597
605
  # Get child's mapper_class and mapping
@@ -606,9 +614,11 @@ module Lutaml
606
614
  if child_mapping
607
615
  # Recursively collect with child's mapping and register context
608
616
  child_needs = NamespaceNeeds.new
609
- child_options = options.merge(
610
- mapper_class: child_type,
611
- )
617
+ child_options = if options[:mapper_class] == child_type
618
+ options
619
+ else
620
+ options.merge(mapper_class: child_type)
621
+ end
612
622
  collect_from_xml_element(child, child_mapping,
613
623
  child_needs, **child_options)
614
624
 
@@ -58,6 +58,7 @@ module Lutaml
58
58
  end
59
59
 
60
60
  (@namespaces ||= {})[key] = usage
61
+ @class_set_version = @class_set_version.to_i + 1
61
62
  end
62
63
 
63
64
  # Track a type namespace for a specific attribute
@@ -66,6 +67,7 @@ module Lutaml
66
67
  def add_type_namespace(attr_name, ns_class)
67
68
  (@type_namespaces ||= {})[attr_name] = ns_class
68
69
  (@type_namespace_classes ||= ::Set.new) << ns_class
70
+ @class_set_version = @class_set_version.to_i + 1
69
71
  end
70
72
 
71
73
  # Add type attribute namespace to tracking set
@@ -73,6 +75,7 @@ module Lutaml
73
75
  def add_type_attribute_namespace(ns_class)
74
76
  (@type_attribute_namespaces ||= ::Set.new) << ns_class
75
77
  (@type_namespace_classes ||= ::Set.new) << ns_class
78
+ @class_set_version = @class_set_version.to_i + 1
76
79
  end
77
80
 
78
81
  # Add type element namespace to tracking set
@@ -80,6 +83,7 @@ module Lutaml
80
83
  def add_type_element_namespace(ns_class)
81
84
  (@type_element_namespaces ||= ::Set.new) << ns_class
82
85
  (@type_namespace_classes ||= ::Set.new) << ns_class
86
+ @class_set_version = @class_set_version.to_i + 1
83
87
  end
84
88
 
85
89
  # Add a type reference for lazy resolution
@@ -136,6 +140,7 @@ module Lutaml
136
140
  @namespaces[key].merge(usage)
137
141
  else
138
142
  @namespaces[key] = usage
143
+ @class_set_version = @class_set_version.to_i + 1
139
144
  end
140
145
  end
141
146
 
@@ -156,6 +161,7 @@ module Lutaml
156
161
  .merge(other.type_attribute_namespaces)
157
162
  (@type_element_namespaces ||= ::Set.new)
158
163
  .merge(other.type_element_namespaces)
164
+ @class_set_version = @class_set_version.to_i + 1
159
165
 
160
166
  # Merge type refs
161
167
  (@type_refs ||= []).concat(other.type_refs)
@@ -205,11 +211,19 @@ module Lutaml
205
211
  end
206
212
  end
207
213
 
208
- # Get all namespace classes (from usage and type namespaces)
214
+ # Get all namespace classes (from usage and type namespaces).
215
+ # Memoized behind a mutation version: the planner asks repeatedly
216
+ # per walk while collection mutates the containers.
209
217
  # @return [Set<Class>]
210
218
  def all_namespace_classes
219
+ version = @class_set_version.to_i
220
+ cached = @all_namespace_classes_memo
221
+ return cached[1] if cached && cached[0] == version
222
+
211
223
  classes = Set.new(namespaces.values.map(&:namespace_class))
212
224
  classes.merge(type_namespace_classes)
225
+ @all_namespace_classes_memo = [version, classes]
226
+ classes
213
227
  end
214
228
 
215
229
  # Validate internal consistency
@@ -15,7 +15,7 @@ module Lutaml
15
15
  # (class, register), bounding the registry; the host object is
16
16
  # the frozen Transformation, so the memo cannot live on it.
17
17
  def element_rule_candidates_registry
18
- @element_rule_candidates_registry ||= {}
18
+ @element_rule_candidates_registry ||= {}.compare_by_identity
19
19
  end
20
20
  end
21
21
  # Apply rules in the order specified by element_order
@@ -170,15 +170,18 @@ model_class, register_id)
170
170
  # module-level registry keyed by the compiled-rules identity: the
171
171
  # reconciler host is the (frozen) Transformation itself, so the
172
172
  # memo lives here. Transformations are cached per (class,
173
- # register), bounding the registry.
173
+ # register), bounding the registry. The lookup is nested
174
+ # (rules identity → element name → namespace URI) so the hit
175
+ # path allocates no key Array.
174
176
  def element_rule_candidates(object, compiled_rules)
175
- registry = OrderedApplier.element_rule_candidates_registry
176
- key = [compiled_rules.object_id, object.name, object.namespace_uri]
177
- cached = registry[key]
177
+ by_rules = OrderedApplier
178
+ .element_rule_candidates_registry[compiled_rules] ||= {}
179
+ by_ns = (by_rules[object.name] ||= {})
180
+ cached = by_ns[object.namespace_uri]
178
181
  return cached if cached
179
182
 
180
183
  object_ns_uri = object.namespace_uri # nil if old element_order (backward compat)
181
- registry[key] = compiled_rules.select do |r|
184
+ by_ns[object_ns_uri] = compiled_rules.select do |r|
182
185
  r.is_a?(::Lutaml::Model::CompiledRule) &&
183
186
  r.option(:mapping_type) == :element &&
184
187
  matches_element_rule?(r, object.name, object_ns_uri)
@@ -15,7 +15,7 @@ module Lutaml
15
15
 
16
16
  def unprefixed_name
17
17
  if namespace_prefix
18
- name.split(":").last
18
+ name[((name.rindex(":") || -1) + 1)..]
19
19
  else
20
20
  name
21
21
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: lutaml-model
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.8.154
4
+ version: 0.8.155
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ribose Inc.