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 +4 -4
- data/lib/moxml/element.rb +18 -3
- data/lib/moxml/materializer.rb +5 -1
- data/lib/moxml/version.rb +1 -1
- data/spec/moxml/element_attribute_pairs_spec.rb +19 -0
- metadata +1 -1
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 3982cbbfe581d8786fa674d3ec8dd1f63900530621265baec4d6e2ff03a5791f
|
|
4
|
+
data.tar.gz: 83906c429efb771af92ba8358a0cd67523d52e7d732cf0ab7e2d6edf1f400af0
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
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
|
-
|
|
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
|
-
|
|
253
|
-
|
|
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
|
data/lib/moxml/materializer.rb
CHANGED
|
@@ -72,7 +72,11 @@ module Moxml
|
|
|
72
72
|
def group_flat(flat, stride)
|
|
73
73
|
return EMPTY_ATTRIBUTES if flat.empty?
|
|
74
74
|
|
|
75
|
-
|
|
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
|
@@ -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
|