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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 59c8df5982f2b80280386a94385ceed9a65b1b80524772d914e19052a564aedd
4
- data.tar.gz: 3e3432a24b65e60bddf345955d4454a5a459f4898693fa9037b71e8a052a6115
3
+ metadata.gz: efd15ef624c00bcb6215f7a120272833f45f4c0f297d2a98b19507540878eec8
4
+ data.tar.gz: 640713084bd178087975387abca9cec4a681c2e94ce905ac16becb5514e25ca2
5
5
  SHA512:
6
- metadata.gz: 3c041e77c6230d320e5a2779f08ffe29505780d4eac520ce1c12c83d5532102153787b592d999067daef2aabfedf08c5a1830d374baa224a9d795e20816faf69
7
- data.tar.gz: 54367812683befdea88202d68a7c15c14b91184e3d350cef9510d94a8e6c769d307f311282041d2816626de181697a8f78b429cb7e71ae2b2d11638d34d0a1f9
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
- adapter.node_type(native) == node_type
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.config.adapter
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)
@@ -23,9 +23,16 @@ module Moxml
23
23
  def each
24
24
  return to_enum(:each) unless block_given?
25
25
 
26
- @nodes.each_with_index do |node, i|
27
- @wrapped[i] ||= wrap_with_parent(node)
28
- yield @wrapped[i]
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
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Moxml
4
- VERSION = "0.5.20"
4
+ VERSION = "0.5.21"
5
5
  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.20
4
+ version: 0.5.21
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ribose Inc.