moxml 0.5.108 → 0.5.110

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: fff38acca654943d1500e6647de3b62fadbb6919e73a1a655c84718a47a08d20
4
- data.tar.gz: cb163aac66d87cb7bb3140bfce8f682791b4cb8430bb435219d3d30141e5ada1
3
+ metadata.gz: 3982cbbfe581d8786fa674d3ec8dd1f63900530621265baec4d6e2ff03a5791f
4
+ data.tar.gz: 83906c429efb771af92ba8358a0cd67523d52e7d732cf0ab7e2d6edf1f400af0
5
5
  SHA512:
6
- metadata.gz: c8ce340193f8f168f5fc06cc12191478dddd56e0debb1e960c43aee2380613350ae3d44e972ba3d1a5084319c3c26902c3ee5aa14ad61c94af57ca259045b1db
7
- data.tar.gz: 771fdc938de78cb25a12830f1257f80c2387ee56916b29c9de46dfa3bb340a3179ed5876498c2c36b22ca4c870f3a70a14c495783aeca73ff68f0eaab59b42f1
6
+ metadata.gz: '0459f6ce8ee1713a840295ce951f19950b1f9e9acffa5ff2949b840fef604468897ae59398aae9bd9a3c1ea0c0b0f6ec591e02e7bf4eaf11dae96d56e3864f61'
7
+ data.tar.gz: 1ed691f3d140ea793f6f94ddef4693dab5155cbf9abbf8c2dce227bf828e2ae976bacf9db7b69839d0f8345f31b2aa6991e7ee6c52acf72ae5628e4bd82e8498
data/lib/moxml/element.rb CHANGED
@@ -122,8 +122,14 @@ module Moxml
122
122
  # per-attribute objects. Names may be shared frozen strings —
123
123
  # dup before mutating. Mutation and per-attribute namespace
124
124
  # resolution stay on #attributes.
125
+ # One C crossing per read re-allocates the row set (moxml#329);
126
+ # memoized on the attribute-value clock — element-side value
127
+ # writes bump it (see invalidate_attribute_value_cache!).
125
128
  def attribute_pairs
126
- adapter.attribute_pairs(@native)
129
+ generation = attribute_value_generation
130
+ @attribute_pairs = nil if @attribute_pairs_gen != generation
131
+ @attribute_pairs_gen = generation
132
+ @attribute_pairs ||= adapter.attribute_pairs(@native)
127
133
  end
128
134
 
129
135
  # Create an element with attributes and attach it under this
@@ -248,9 +254,18 @@ module Moxml
248
254
  alias add_namespace_definition add_namespace
249
255
 
250
256
  # it's NOT the same as namespaces.first
257
+ # Per-read namespace resolution pays an FFI fetch plus a wrapper
258
+ # mint on every call (moxml#329: a top attribution site in the
259
+ # fallback-path census). Memoized on the namespace-scope clock —
260
+ # every scope mutation bumps it (see invalidate_namespace_cache!).
251
261
  def namespace
252
- ns = adapter.namespace(@native)
253
- ns && Wrappers::Namespace.new(ns, context)
262
+ generation = context.namespace_scope_generation
263
+ @namespace = nil if @namespace_gen != generation
264
+ @namespace_gen = generation
265
+ @namespace ||= begin
266
+ ns = adapter.namespace(@native)
267
+ ns && Wrappers::Namespace.new(ns, context)
268
+ end
254
269
  end
255
270
 
256
271
  # add the prefix to the element name
@@ -72,7 +72,11 @@ module Moxml
72
72
  def group_flat(flat, stride)
73
73
  return EMPTY_ATTRIBUTES if flat.empty?
74
74
 
75
- flat.each_slice(stride).to_a
75
+ # Direct indexing over each_slice: no enumerator chain per
76
+ # record (moxml#329's slice-churn row — the enumerator
77
+ # allocation dominated the sub-array cost on deep trees).
78
+ count = flat.size / stride
79
+ Array.new(count) { |i| flat[i * stride, stride] }
76
80
  end
77
81
  end
78
82
 
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.108"
4
+ VERSION = "0.5.110"
5
5
  end
@@ -39,4 +39,23 @@ RSpec.describe Moxml::Element do
39
39
  end
40
40
  end
41
41
  end
42
+
43
+ context "when memoized" do
44
+ it "returns the same object on repeated reads" do
45
+ with_adapter(:leptris) do |ctx|
46
+ root = ctx.parse(xml).root
47
+ expect(root.attribute_pairs).to equal(root.attribute_pairs)
48
+ end
49
+ end
50
+
51
+ it "refreshes after a value write" do
52
+ with_adapter(:leptris) do |ctx|
53
+ root = ctx.parse(xml).root
54
+ before = root.attribute_pairs
55
+ root["id"] = "r9"
56
+ expect(root.attribute_pairs).not_to equal(before)
57
+ expect(root.attribute_pairs).to include(["id", "r9"])
58
+ end
59
+ end
60
+ end
42
61
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: moxml
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.5.108
4
+ version: 0.5.110
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ribose Inc.