moxml 0.5.20 → 0.5.21
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/entity.rb +10 -0
- data/lib/moxml/node.rb +12 -2
- data/lib/moxml/node_set.rb +10 -3
- data/lib/moxml/version.rb +1 -1
- 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: efd15ef624c00bcb6215f7a120272833f45f4c0f297d2a98b19507540878eec8
|
|
4
|
+
data.tar.gz: 640713084bd178087975387abca9cec4a681c2e94ce905ac16becb5514e25ca2
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 2d418bb84689e70721a4e9b16359136e94d781d7da0bc2c9b7374f58ff911d08fff0eb874a8ed31a6434b9d953381714ad8d1dad5911a6b457b8ae6143a53491
|
|
7
|
+
data.tar.gz: 6aca55287d55514bd1dfc52c4286909760fb2b9230c33989c21bda4b78d873977ca07ef30df165413d959a42cd7ffa052677aaae672dfe1884f6e84af3b270c5
|
data/lib/moxml/entity.rb
CHANGED
|
@@ -43,6 +43,12 @@ module Moxml
|
|
|
43
43
|
SERIALIZED_MARKER_RE = /(#{NAME_PATTERN});/
|
|
44
44
|
STANDARD_ENTITIES = %w[amp lt gt quot apos].freeze
|
|
45
45
|
|
|
46
|
+
# One regex pass, no allocations: true when a NON-standard named
|
|
47
|
+
# entity exists somewhere. Documents carrying only the five
|
|
48
|
+
# predefined entities (the overwhelmingly common case) skip the
|
|
49
|
+
# marker gsub's full-buffer copy entirely.
|
|
50
|
+
NON_STANDARD_ENTITY_RE = /&(?!amp;|lt;|gt;|quot;|apos;)(#{NAME_PATTERN});/
|
|
51
|
+
|
|
46
52
|
NAMED_DECODE_MAP = {
|
|
47
53
|
"amp" => "&", "lt" => "<", "gt" => ">",
|
|
48
54
|
"quot" => '"', "apos" => "'"
|
|
@@ -82,6 +88,10 @@ module Moxml
|
|
|
82
88
|
# the regex scan and string allocation entirely. The vast
|
|
83
89
|
# majority of XML payloads contain no entity references.
|
|
84
90
|
return [str, false] unless str.include?("&")
|
|
91
|
+
# Second fast path: only predefined entities — the gsub would
|
|
92
|
+
# pass every match through unchanged, so skip its full-buffer
|
|
93
|
+
# copy too.
|
|
94
|
+
return [str, false] unless str.match?(NON_STANDARD_ENTITY_RE)
|
|
85
95
|
|
|
86
96
|
marked = false
|
|
87
97
|
processed = str.gsub(NAME_RE) do |match|
|
data/lib/moxml/node.rb
CHANGED
|
@@ -339,10 +339,18 @@ module Moxml
|
|
|
339
339
|
|
|
340
340
|
TYPES.each do |node_type|
|
|
341
341
|
define_method "#{node_type}?" do
|
|
342
|
-
|
|
342
|
+
node_type_cached == node_type
|
|
343
343
|
end
|
|
344
344
|
end
|
|
345
345
|
|
|
346
|
+
# The adapter's type probe is an FFI call per invocation; the
|
|
347
|
+
# type is fixed for a node's lifetime, so the first answer is
|
|
348
|
+
# memoized on the wrapper.
|
|
349
|
+
def node_type_cached
|
|
350
|
+
@node_type_cached ||= adapter.node_type(@native)
|
|
351
|
+
end
|
|
352
|
+
private :node_type_cached
|
|
353
|
+
|
|
346
354
|
# Returns the primary identifier for this node type
|
|
347
355
|
# For Element: the tag name
|
|
348
356
|
# For Attribute: the attribute name
|
|
@@ -392,7 +400,9 @@ module Moxml
|
|
|
392
400
|
protected
|
|
393
401
|
|
|
394
402
|
def adapter
|
|
395
|
-
context
|
|
403
|
+
# A context's adapter object is fixed for its lifetime; the
|
|
404
|
+
# chain deref ran on every node access.
|
|
405
|
+
@adapter ||= context.config.adapter
|
|
396
406
|
end
|
|
397
407
|
|
|
398
408
|
def self.adapter(context)
|
data/lib/moxml/node_set.rb
CHANGED
|
@@ -23,9 +23,16 @@ module Moxml
|
|
|
23
23
|
def each
|
|
24
24
|
return to_enum(:each) unless block_given?
|
|
25
25
|
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
26
|
+
wrapped = @wrapped
|
|
27
|
+
index = 0
|
|
28
|
+
@nodes.each do |node|
|
|
29
|
+
wrapper = wrapped[index]
|
|
30
|
+
unless wrapper
|
|
31
|
+
wrapper = wrap_with_parent(node)
|
|
32
|
+
wrapped[index] = wrapper
|
|
33
|
+
end
|
|
34
|
+
yield wrapper
|
|
35
|
+
index += 1
|
|
29
36
|
end
|
|
30
37
|
self
|
|
31
38
|
end
|
data/lib/moxml/version.rb
CHANGED