lutaml-model 0.8.149 → 0.8.151

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: '05094b330515b62b69ce8a2576cdf74b7e5441358210ef20191d5e1ee6eca0fd'
4
- data.tar.gz: 1a97398db1d90288bd121c355136e64e1d68df8d5c93dfc7a2d4812da062b538
3
+ metadata.gz: adfeae6e61819206738de78eb4929879eccf78883e990f316693fcaa6e6ab6f5
4
+ data.tar.gz: 99579af55daa357c72ce11b78d10839c4ceb02828f45f8b2bbd35eae735ba0ee
5
5
  SHA512:
6
- metadata.gz: ad0eb3a038d4a6f380ccae5336187ca306b253a4708163c76ec2296e82b6605200f1eb91760f6333381c78a0ee260b7013137f2ffdfce6cc9015097931eadb78
7
- data.tar.gz: 5381dfdafa4829d1ef964d94cfdeb3c9ce4c895f2eba6fa5d84a74ee20a3ec2ae6f1ff0dbab387dd220b405f180bfa1abcc2663e7ca41d8235da96a82280752c
6
+ metadata.gz: 53c2c071eb6ee0fd327f7f0defbf5be45812289c468cdec6441ea9b20f52c6605bed1d593de9b2031d6c6b8870229f358eed072b800c122f16d28bdb9991f1ac
7
+ data.tar.gz: 17467fa3f3f51db8bde7ae876b9707f06bb45148cbdfae7a1e8637a188162fcf0c1b5d0baab8612c04931423fec39ba9dbcd972d2f9497822571b77af308c576
@@ -56,5 +56,14 @@ jobs:
56
56
  - name: Install dependencies
57
57
  run: bundle install
58
58
 
59
+ - name: Pin moxml to the 0.5 line for the Opal boot
60
+ # moxml 0.6 deleted lib/compat/opal (moxml#516) and the boot
61
+ # manifest appends that path (#914); the lane stays on 0.5.x
62
+ # until it migrates to the moxml-ts wasm binding. The gemspec
63
+ # admits both lines (>= 0.5.139, < 0.7), so this lockfile-local
64
+ # pin selects the Opal-compatible one without restricting
65
+ # CRuby consumers.
66
+ run: bundle update moxml --version '~> 0.5.139'
67
+
59
68
  - name: Run Opal tests
60
69
  run: bundle exec rake spec:opal
@@ -613,11 +613,12 @@ module Lutaml
613
613
  register_id = instance.lutaml_register
614
614
  attrs_by = attributes(register_id)
615
615
  writers = instantiate_writers(register_id)
616
+ raw_readers = instantiate_raw_readers(register_id)
616
617
  given = 0
617
618
  # Memoized pair array: Hash#each mints a [name, attr] pair
618
619
  # per attribute per instance (~5 allocs/instance on
619
620
  # hydration-heavy corpora); Array#each reuses its elements.
620
- instantiate_attr_pairs(register_id).each do |name, attr|
621
+ instantiate_attr_pairs(register_id).each do |name, attr, str_name|
621
622
  next if attr.derived?
622
623
 
623
624
  # Symbol keys hit directly (native-extension callers);
@@ -625,7 +626,7 @@ module Lutaml
625
626
  key = if attrs.key?(name)
626
627
  given += 1
627
628
  name
628
- elsif (str_name = name.to_s) && attrs.key?(str_name)
629
+ elsif attrs.key?(str_name)
629
630
  given += 1
630
631
  str_name
631
632
  end
@@ -647,7 +648,7 @@ module Lutaml
647
648
  # only then is the default seeded. The writer's own
648
649
  # value_set_for (inside the compiled writer) already
649
650
  # marked it set, so it renders.
650
- raw = instance.public_send(:"__lutaml_raw_#{name}")
651
+ raw = instance.public_send(raw_readers[name])
651
652
  unset = raw.nil? ||
652
653
  raw.equal?(Lutaml::Model::UninitializedClass.instance) ||
653
654
  raw.equal?(Lutaml::Model::Serialize::LAZY_EMPTY_COLLECTION)
@@ -688,7 +689,24 @@ module Lutaml
688
689
  # pair array disappears (see the instantiate comment).
689
690
  def instantiate_attr_pairs(register_id = nil)
690
691
  (@instantiate_attr_pairs ||= {})[register_id] ||=
691
- attributes(register_id).to_a.freeze
692
+ attributes(register_id).map do |name, attr|
693
+ # The string name is precomputed beside the symbol: the
694
+ # absent-key fallback (string-keyed callers, from_hash)
695
+ # would otherwise mint `name.to_s` per attribute per
696
+ # instance — one fresh string per absent attribute.
697
+ [name, attr, name.to_s]
698
+ end.freeze
699
+ end
700
+
701
+ # Raw-state reader names, precomputed once per (class, register):
702
+ # instantiating interpolates the reader symbol per absent
703
+ # attribute per instance otherwise — a fresh string + symbol
704
+ # lookup for state that is identical for every instance.
705
+ def instantiate_raw_readers(register_id = nil)
706
+ (@instantiate_raw_readers ||= {})[register_id] ||=
707
+ attributes(register_id).to_h do |name, _|
708
+ [name, :"__lutaml_raw_#{name}"]
709
+ end.freeze
692
710
  end
693
711
 
694
712
  # Define register-specific attribute methods on the class itself.
@@ -2,6 +2,6 @@
2
2
 
3
3
  module Lutaml
4
4
  module Model
5
- VERSION = "0.8.149"
5
+ VERSION = "0.8.151"
6
6
  end
7
7
  end
@@ -1460,11 +1460,22 @@ module Lutaml
1460
1460
  # Raw xsi:schemaLocation capture must stay out of the way, or the
1461
1461
  # writer re-emits the value beside the mapped attribute (#1042).
1462
1462
  def schema_location_mapped?(register_id = nil)
1463
- mapping_attributes_hash(register_id).each_value.any? do |rule_or_array|
1463
+ # Memoized per register against the mapping's rule-records
1464
+ # version: the walk re-asks per parse, and the un-memoized form
1465
+ # allocated a merged attributes hash plus a name string per rule
1466
+ # per ask.
1467
+ version = rule_records_version.to_i
1468
+ cache = (@schema_location_mapped ||= {})
1469
+ cached = cache[register_id]
1470
+ return cached[:value] if cached && cached[:version] == version
1471
+
1472
+ value = mapping_attributes_hash(register_id).each_value.any? do |rule_or_array|
1464
1473
  Array(rule_or_array).any? do |rule|
1465
1474
  rule.name.to_s == "schemaLocation"
1466
1475
  end
1467
1476
  end
1477
+ cache[register_id] = { version: version, value: value }
1478
+ value
1468
1479
  end
1469
1480
 
1470
1481
  # Raw hash access for inheritance and deep_dup operations.
@@ -9,6 +9,15 @@ module Lutaml
9
9
  # from XML) AND the mapping is marked as ordered, this module ensures
10
10
  # the original XML structure is preserved during serialization.
11
11
  module OrderedApplier
12
+ class << self
13
+ # Memo registry for the ordered reconcile (see
14
+ # #element_rule_candidates). Transformations are cached per
15
+ # (class, register), bounding the registry; the host object is
16
+ # the frozen Transformation, so the memo cannot live on it.
17
+ def element_rule_candidates_registry
18
+ @element_rule_candidates_registry ||= {}
19
+ end
20
+ end
12
21
  # Apply rules in the order specified by element_order
13
22
  #
14
23
  # This ensures round-trip serialization preserves the original XML structure.
@@ -143,25 +152,37 @@ model_class, register_id)
143
152
  return nil unless order_entry?(object)
144
153
  return nil unless object.type == "Element"
145
154
 
146
- object_ns_uri = object.namespace_uri # nil if old element_order (backward compat)
155
+ # The matching candidate list is deterministic per (compiled
156
+ # rules, name, namespace) — memoize it so each distinct element
157
+ # spelling pays the rule scan once per serialize, not once per
158
+ # element object (#1059-era ordered reconciles scan linearly
159
+ # otherwise).
160
+ candidates = element_rule_candidates(object, compiled_rules)
161
+
162
+ first = candidates.first
163
+ return nil unless first
164
+ return first if candidates.size == 1
165
+
166
+ resolve_shared_name_rule(object, candidates)
167
+ end
168
+
169
+ # Matching element rules for one element spelling, memoized in a
170
+ # module-level registry keyed by the compiled-rules identity: the
171
+ # reconciler host is the (frozen) Transformation itself, so the
172
+ # memo lives here. Transformations are cached per (class,
173
+ # register), bounding the registry.
174
+ 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]
178
+ return cached if cached
147
179
 
148
- first = nil
149
- shared_name = false
150
- compiled_rules.each do |r|
151
- next unless r.is_a?(::Lutaml::Model::CompiledRule) &&
180
+ object_ns_uri = object.namespace_uri # nil if old element_order (backward compat)
181
+ registry[key] = compiled_rules.select do |r|
182
+ r.is_a?(::Lutaml::Model::CompiledRule) &&
152
183
  r.option(:mapping_type) == :element &&
153
184
  matches_element_rule?(r, object.name, object_ns_uri)
154
-
155
- if first.nil?
156
- first = r
157
- else
158
- shared_name = true
159
- break
160
- end
161
185
  end
162
- return first unless shared_name
163
-
164
- resolve_shared_name_rule(object, compiled_rules, object_ns_uri)
165
186
  end
166
187
 
167
188
  private
@@ -210,13 +231,9 @@ model_class, register_id)
210
231
  # ones. Entries matching no discriminator pair — an unknown value,
211
232
  # or an entry without attributes — fall back to the first plain
212
233
  # rule.
213
- def resolve_shared_name_rule(object, compiled_rules, object_ns_uri)
234
+ def resolve_shared_name_rule(object, candidates)
214
235
  plain = nil
215
- compiled_rules.each do |r|
216
- next unless r.is_a?(::Lutaml::Model::CompiledRule) &&
217
- r.option(:mapping_type) == :element &&
218
- matches_element_rule?(r, object.name, object_ns_uri)
219
-
236
+ candidates.each do |r|
220
237
  pairs = rule_discriminator(r)
221
238
  return r if pairs && entry_matches_when_attribute?(object, pairs)
222
239
 
data/lutaml-model.gemspec CHANGED
@@ -41,7 +41,14 @@ Gem::Specification.new do |spec|
41
41
  # 0.5.84 always passes XML_PARSE_HUGE to libxml2: very large documents
42
42
  # parse completely instead of being silently truncated at the 10 MB
43
43
  # input-buffer cap (lutaml-model#871).
44
- spec.add_dependency "moxml", "~> 0.5.139"
44
+ # moxml 0.6.0 removed the Opal surface (lutaml/moxml#516, the
45
+ # cross-language program's phase 4); the CRuby facade faces this
46
+ # gem uses are unchanged, and the full suite is green on the 0.6
47
+ # line. Admit BOTH lines so CRuby consumers resolve 0.6.x while
48
+ # the Opal boot lane (#914) pins its own ~> 0.5.x (lib/compat/opal
49
+ # exists only on 0.5) until it migrates to the moxml-ts wasm
50
+ # binding.
51
+ spec.add_dependency "moxml", ">= 0.5.139", "< 0.7"
45
52
  spec.add_dependency "ostruct"
46
53
  spec.add_dependency "rubyzip", "~> 3.7"
47
54
  spec.add_dependency "thor", "~> 1.4"
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.149
4
+ version: 0.8.151
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ribose Inc.
@@ -90,16 +90,22 @@ dependencies:
90
90
  name: moxml
91
91
  requirement: !ruby/object:Gem::Requirement
92
92
  requirements:
93
- - - "~>"
93
+ - - ">="
94
94
  - !ruby/object:Gem::Version
95
95
  version: 0.5.139
96
+ - - "<"
97
+ - !ruby/object:Gem::Version
98
+ version: '0.7'
96
99
  type: :runtime
97
100
  prerelease: false
98
101
  version_requirements: !ruby/object:Gem::Requirement
99
102
  requirements:
100
- - - "~>"
103
+ - - ">="
101
104
  - !ruby/object:Gem::Version
102
105
  version: 0.5.139
106
+ - - "<"
107
+ - !ruby/object:Gem::Version
108
+ version: '0.7'
103
109
  - !ruby/object:Gem::Dependency
104
110
  name: ostruct
105
111
  requirement: !ruby/object:Gem::Requirement