lutaml-model 0.8.153 → 0.8.154

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: 6a43c96db13151bde996328f404ea863bcca41342ba8aade9af50b0337a876ba
4
- data.tar.gz: 1c243c3811902784fce7995ddc414a0c5d2f0a65a0d7e46e0ee26099f72137b2
3
+ metadata.gz: 6be6e9b6e0d81dbc991b1d7cda6e6a81101108775c4638f09388bd508a8e2f38
4
+ data.tar.gz: 4d3807bd5c51e9c5d2554bbf72f875eb2f055d214fc6efcaa670a161cf7de21e
5
5
  SHA512:
6
- metadata.gz: ec4add92a4e7d1bab0390c926e9449a3978caf671a3a44a62441606d666e367ff9f960e3649443141ba69017bae76e1089b9c478f5f69f572b78a269abdccc65
7
- data.tar.gz: b0b9818d4208443291e23c38cb5640220e8b748fffdd8aa452d2e40397cfe0781095478aef0ec89219368a6ef6fe06560a97a4ba6b6a057c91f9307b1a7c49b4
6
+ metadata.gz: a35214810fd059595ce1cd8ed7d8e7cbeb4d8286da37f9a3a55dfcdd923147e9d8a8b003f6a216c2237dd2cdc21e238194a5a1ac7c9b056f34e3cfae9e8b7549
7
+ data.tar.gz: 025c3a00a72de6a7e89a102d7b4ccfbd52f08d357f5a33a5771055330acb2eb93cba406f53e51e6cd05891171418f488775d9128d07f7752be881a99bb729a99
@@ -65,7 +65,9 @@ model_class: nil)
65
65
  # nested-model classification — resolve once per rule; the
66
66
  # per-field hash lookups dominated primitive-heavy docs.
67
67
  plan = serialize_plan(rule)
68
- if (fast = plan[:identity_type]) && value.instance_of?(fast)
68
+ if plan[:identity_type] &&
69
+ !value.is_a?(::Lutaml::Model::Serialize) &&
70
+ !value.is_a?(::Hash) && !value.is_a?(::Array)
69
71
  return value
70
72
  end
71
73
 
@@ -160,7 +162,13 @@ model_class: nil)
160
162
  # (no custom to AND no custom from): a custom from means the
161
163
  # wrapper constructor normalizes the value, so the raw value
162
164
  # must still pass through it.
163
- if plan[:identity_type] && value.instance_of?(plan[:identity_type])
165
+ # No custom to_<format> serializer means the wrapper's
166
+ # to_<format> is the inherited identity — the raw value IS the
167
+ # serialized form, whatever its class (the old
168
+ # value.instance_of?(TypeClass) check could never match raw
169
+ # scalars, so every Integer/Boolean/String paid the
170
+ # wrap-allocate-cast ceremony).
171
+ if plan[:identity_type] && !value.is_a?(::Lutaml::Model::Serialize) && !value.is_a?(::Hash) && !value.is_a?(::Array)
164
172
  return value
165
173
  end
166
174
  if (to_fn = plan[:to_fn])
@@ -227,9 +235,12 @@ model_class: nil)
227
235
 
228
236
  serializer = ::Lutaml::Model::Type::Value
229
237
  .format_type_serializer_for(@format, type)
230
- has_custom_to = serializer && serializer[:to]
231
- has_custom_from = ::Lutaml::Model::Attribute.custom_from_probe?(type)
232
- type unless has_custom_to || has_custom_from
238
+ # Only a registered custom to_<format> serializer blocks the
239
+ # identity path: #to_<format>'s default is the inherited identity,
240
+ # so the wrapper ceremony is a no-op for every other type. (The
241
+ # custom FROM probe is a parse-direction concern and does not
242
+ # change what serialization emits.)
243
+ serializer && serializer[:to] ? nil : type
233
244
  end
234
245
 
235
246
  private
@@ -421,7 +421,37 @@ module Lutaml
421
421
  self.class.cast_type!(type)
422
422
  end
423
423
 
424
+ # Per-(attribute, register) memo for the dominant scalar case: the
425
+ # resolved type is a plain Type::Value with no custom probes, the
426
+ # attribute is not a collection/union/reference, and the input is a
427
+ # String (the shape every wire format hands over). The full cast
428
+ # chain resolves the same type and lands on the same
429
+ # `resolved_type.cast(value)` call — this skips the eight
430
+ # intermediate checks per value. Generation-guarded like
431
+ # #type's register cache: a replaced register context flushes it.
432
+ def fast_scalar_type(register)
433
+ generation = GlobalContext.context_generation
434
+ cache = (@fast_scalar_types ||= {}.compare_by_identity)
435
+ if @fast_scalar_generation != generation
436
+ cache.clear
437
+ @fast_scalar_generation = generation
438
+ end
439
+
440
+ cache[register] ||= begin
441
+ resolved = type(register)
442
+ resolved if resolved.is_a?(Class) &&
443
+ resolved < Lutaml::Model::Type::Value &&
444
+ resolved != Lutaml::Model::Type::Hash &&
445
+ !union? && !collection? && @options[:ref_model_class].nil? &&
446
+ !self.class.custom_from_probe?(resolved)
447
+ end
448
+ end
449
+
424
450
  def cast_value(value, register)
451
+ if value.is_a?(::String) && (fast = fast_scalar_type(register))
452
+ return fast.cast(value)
453
+ end
454
+
425
455
  if list_like?(value)
426
456
  items = cast_items(value, register)
427
457
  elsif coerce_to_collection?(value)
@@ -2,6 +2,6 @@
2
2
 
3
3
  module Lutaml
4
4
  module Model
5
- VERSION = "0.8.153"
5
+ VERSION = "0.8.154"
6
6
  end
7
7
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: lutaml-model
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.8.153
4
+ version: 0.8.154
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ribose Inc.
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2026-10-31 00:00:00.000000000 Z
11
+ date: 2026-11-01 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: base64