moxml 0.5.1 → 0.5.2

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: ca6fefbf114afcaf13d9c241b4df5081eef1e004019618ca12d31a655d89dd53
4
- data.tar.gz: d361373f16dafff997d4ca53b5dbc23c332b09331e8f49ef5abed09f526bdea7
3
+ metadata.gz: 566f12c7bcda29e079d0fd5b496a6becff643b9c15afd328d5f99fb7ef70d35c
4
+ data.tar.gz: a4d7858218db7d38300b963b11d5e40b5aec176d2072a177c4e5448f839b8671
5
5
  SHA512:
6
- metadata.gz: 0a2e61a613511970e4c6945c074a578aefcb12591def797a726bf0959796c43dbf2e71b77509271b1dad15b9f0f1e81f5ec3b8b0af0e384bccad35745bc2dbb6
7
- data.tar.gz: 183964ef083c888b3b7d58b896a547acf25c0414d997040c10b805b8379088825c2ec996b149aa9e8fe51b6419135d1341d8ebe9c88ddb0656101e25d3291557
6
+ metadata.gz: 45cf69a5c753718d3bcef44580ef2e8e0dcfa536033537602952e8cbeb73e8bb59e68ad365fdc72c6b7422a998c50e623a1f7b894ed5e7da3cd8e129ff40c703
7
+ data.tar.gz: 0fd18d4891bd29ce56ab1174aa494f8dddc251d298067a0290bf84df41f6854d61bdeedf6e9fd813c32669a9a550419865a637633ddd6e558e84ff0d9f6eca2e
@@ -546,6 +546,10 @@ module Moxml
546
546
  # returns those without name accessors). Both engines resolve
547
547
  # expression prefixes against document-declared namespaces.
548
548
  NATIVE_XPATH_CACHE = XPath::Cache.new(100)
549
+ # The gate decision is expression-intrinsic; re-walking the
550
+ # cached AST three times per xpath call cost ~23% of repeated
551
+ # selective queries, so the boolean caches beside it.
552
+ NATIVE_GATE_CACHE = XPath::Cache.new(100)
549
553
 
550
554
  def xpath(node, expression, namespaces = {})
551
555
  native = native_xpath(node, expression, namespaces)
@@ -623,11 +627,13 @@ module Moxml
623
627
  # attribute-node results, or the nokogiri-compat xmlns:
624
628
  # reserved prefix convention.
625
629
  def native_expression?(expression)
626
- ast = XPath::Parser.parse_with_cache(expression)
627
- return false if ast_contains_type?(ast, :variable)
628
- return false if uses_xmlns_prefix?(ast)
630
+ NATIVE_GATE_CACHE.get_or_set(expression) do
631
+ ast = XPath::Parser.parse_with_cache(expression)
632
+ next false if ast_contains_type?(ast, :variable)
633
+ next false if uses_xmlns_prefix?(ast)
629
634
 
630
- !selects_attribute_results?(ast)
635
+ !selects_attribute_results?(ast)
636
+ end
631
637
  rescue XPath::SyntaxError
632
638
  false
633
639
  end
@@ -7,6 +7,11 @@ require "libxml"
7
7
  module Moxml
8
8
  module Adapter
9
9
  class Libxml < Base
10
+ # DOCTYPE prolog sniffer; see parse for the index-then-match
11
+ # strategy that keeps this off the hot path.
12
+ DOCTYPE_RE = /<!DOCTYPE\s+([^\s>]+)(?:\s+PUBLIC\s+"([^"]+)"\s+"([^"]+)"|\s+SYSTEM\s+"([^"]+)")?\s*>/i
13
+ private_constant :DOCTYPE_RE
14
+
10
15
  autoload :EntityRefRegistry, "moxml/adapter/libxml/entity_ref_registry"
11
16
 
12
17
  # Wrapper class to store DOCTYPE information
@@ -89,8 +94,15 @@ module Moxml
89
94
  # parameter or XML declaration for byte interpretation.
90
95
  xml_string = preprocess_entities(xml_string)
91
96
 
92
- # Extract DOCTYPE before parsing
93
- doctype_match = xml_string.match(/<!DOCTYPE\s+([^\s>]+)(?:\s+PUBLIC\s+"([^"]+)"\s+"([^"]+)"|\s+SYSTEM\s+"([^"]+)")?\s*>/i)
97
+ # Extract DOCTYPE before parsing. Locate the literal first:
98
+ # a plain memscan is ~2x cheaper than the regex's literal
99
+ # prefix scan on doctype-less documents (the common case),
100
+ # and matching from the found offset keeps captures
101
+ # identical.
102
+ doctype_idx = xml_string.index("<!DOCTYPE")
103
+ doctype_match = if doctype_idx
104
+ xml_string.match(DOCTYPE_RE, doctype_idx)
105
+ end
94
106
 
95
107
  native_doc = begin
96
108
  # Handle both string and file inputs
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.1"
4
+ VERSION = "0.5.2"
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.1
4
+ version: 0.5.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ribose Inc.