moxml 0.5.121 → 0.5.122

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: 3e70385e5a2ffc34bc69d65011c6fead0dfdb3311ac44d68893990b714aa750b
4
- data.tar.gz: 1d7d88feac80fdef1a56a5e09d333ee350bd9e2cc19c42a26e57a5283e8ab8ef
3
+ metadata.gz: 5366b1e4d4b177747964da2c010c7b45a93fd31d71b0ec06b531c87fcee8fd95
4
+ data.tar.gz: d7bd6f17cadea96f07c861dcd753201076e9f5b98c7f60c9ac8d965bdfe6cbfc
5
5
  SHA512:
6
- metadata.gz: 846a93feb34b6de7dab678e91b72cfe8691b17fab1987605906919225ce406204b4beb2dbae3d8e95b54bdf42f1ec9895598c22e49d3816d866241f5cb6e0fad
7
- data.tar.gz: 915721b24c27eef6790fa31f22f82dd1f6b3d2998b9c5824c4515a50f4d0500ff2bd40874b414f8a02dce433d90455eda067dd07f35ad127df46182dac8133a1
6
+ metadata.gz: '0980aadf7e42a333fa96984c945b7b2b4954ca7fefa32972e5ac29dd85a27b1334a461b88f278769a70776e7207f684848e588735d47ddb66420a5781fd1542a'
7
+ data.tar.gz: 51a9461b90b4df2b5a56c47f68f35f6eaf4338822bb153c9ec5d53db05b390540e16f516f5bcc72c30dc376297551f8d3e0e1f623d4464f93ac821cf7c8b6048
data/lib/moxml/version.rb CHANGED
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Moxml
4
- VERSION = "0.5.121"
4
+ VERSION = "0.5.122"
5
5
  end
data/lib/moxml/xsd.rb CHANGED
@@ -57,11 +57,29 @@ module Moxml
57
57
  end
58
58
 
59
59
  # Validate a node or raw XML string. Returns [] when valid.
60
+ # FROZEN string sources parse once and are memoized for the
61
+ # schema's lifetime — re-validating the same document is the
62
+ # hot consumer shape, and a per-call parse costs the full
63
+ # document pool every time (moxml#350's MB-per-validate
64
+ # growth). Unfrozen strings re-parse (mutation must be
65
+ # visible); pass a Moxml::Document to control the parse
66
+ # yourself.
60
67
  def validate(node_or_xml)
61
68
  doc = case node_or_xml
62
69
  when Moxml::Document then node_or_xml
63
70
  when Moxml::Node then node_or_xml.document
64
- else @context.parse(node_or_xml.to_s)
71
+ else
72
+ cached = @parsed_source
73
+ if cached && node_or_xml.frozen? &&
74
+ cached[0].equal?(node_or_xml)
75
+ cached[1]
76
+ else
77
+ parsed = @context.parse(node_or_xml.to_s)
78
+ if node_or_xml.frozen?
79
+ @parsed_source = [node_or_xml, parsed]
80
+ end
81
+ parsed
82
+ end
65
83
  end
66
84
  @context.config.adapter.xsd_validate(@handle, doc.native)
67
85
  end
@@ -101,6 +101,28 @@ RSpec.describe Moxml::XSD do
101
101
  end
102
102
  end
103
103
 
104
+ it "memoizes the parse for frozen string sources (moxml#350)" do
105
+ schema = ctx.xsd(schema_text)
106
+ source = "<note><to>You</to></note>"
107
+ first = schema.validate(source)
108
+ parsed = schema.instance_variable_get(:@parsed_source)
109
+ expect(parsed[0]).to equal(source)
110
+ 3.times { schema.validate(source) }
111
+ # same source object, one parse — the memo entry is untouched
112
+ expect(schema.instance_variable_get(:@parsed_source)[1])
113
+ .to equal(parsed[1])
114
+ expect(first).to eq([])
115
+ end
116
+
117
+ it "re-parses unfrozen string sources (mutation stays visible)" do
118
+ schema = ctx.xsd(schema_text)
119
+ mutable = +"<note><to>You</to></note>"
120
+ expect(schema.valid?(mutable)).to be(true)
121
+ mutable.replace("<note><wrong/></note>")
122
+ expect(schema.valid?(mutable)).to be(false)
123
+ expect(schema.instance_variable_get(:@parsed_source)).to be_nil
124
+ end
125
+
104
126
  it "derives XSD_SUPPORTED from the engine face gate" do
105
127
  # The capability flag must not outrun the engine faces: a
106
128
  # misreleased lockstep (NATIVE_PLAN_STRUCTS lesson) would arm
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: moxml
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.5.121
4
+ version: 0.5.122
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-10 00:00:00.000000000 Z
11
+ date: 2026-10-11 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description: |
14
14
  Moxml is a unified XML manipulation library that provides a common API