canon 0.3.16 → 0.3.18

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: 133da0e86ad37cf095f738d15a37ebcc3b35ae92240327d459ed1d1bbedc3a5b
4
- data.tar.gz: 6c7c2cf6e60712058a6f49f28cf9181316f9e410da5a3982b72fee7fdebde115
3
+ metadata.gz: b27c3659e1b75307f170fb50161ce649c54ab4a12600716d3b006fce8b01ad1a
4
+ data.tar.gz: 89c288d724f4a3b0b410938d94959880b4fbbcff1ec550b53593840bd33d52c8
5
5
  SHA512:
6
- metadata.gz: fd39028ce4e945d04ac83d44f9a0da8b516dadf8a454bb634147aabfa480f896ed25f7cf048b39d6b0173a6a1b6aab2881a607b6e8588ff124d4616f95fb944c
7
- data.tar.gz: 20eedf19bb73922d482537bfe8411bf8b8816001a4df6d59130f08558d80e14d2bfd968c9029d176cae056b0a4d9b1c36d16fb4012329073cceb490846462f7a
6
+ metadata.gz: '0922a2a6d6061f7472ac55de8c6e0172a8ce8d2939f8f144f71493b148248fb597c07d916c67dc9a4549d35a6e65b7757e5cb3f0d0ae79a7a39f7b35306bbb22'
7
+ data.tar.gz: e5b5b898ca11ef0bdc077d8cfb78d6575bc7c9a6b712f2a0ccbd2a3f338704d66883c730e32651af1776746b751b996c723b29af80044d8cd44944f9b18df883
@@ -24,6 +24,15 @@ module Canon
24
24
  return Comparison::UNEQUAL_TYPES
25
25
  end
26
26
 
27
+ # FAST PATH: deep-equal objects in identical key order — every
28
+ # nested comparison is trivially equivalent and no key-order
29
+ # difference exists (strict key_order compares insertion
30
+ # order, which keys == keys preserves). Most object pairs in
31
+ # similar documents hit this and skip the path-building walk.
32
+ if obj1 == obj2 && (!obj1.is_a?(Hash) || obj1.keys == obj2.keys)
33
+ return Comparison::EQUIVALENT
34
+ end
35
+
27
36
  case obj1
28
37
  when Hash
29
38
  compare_hashes(obj1, obj2, opts, differences, path)
@@ -23,8 +23,12 @@ module Canon
23
23
  def self.sort_json_keys(obj)
24
24
  case obj
25
25
  when Hash
26
- obj.transform_values { |v| sort_json_keys(v) }
27
- .sort.to_h
26
+ # Single pass: sorted keys once, one rebuilt hash. The
27
+ # previous form (transform_values + sort.to_h) rebuilt every
28
+ # container twice per canonicalization.
29
+ sorted = {}
30
+ obj.keys.sort.each { |key| sorted[key] = sort_json_keys(obj[key]) }
31
+ sorted
28
32
  when Array
29
33
  obj.map { |item| sort_json_keys(item) }
30
34
  else
@@ -23,8 +23,12 @@ module Canon
23
23
  def self.sort_yaml_keys(obj)
24
24
  case obj
25
25
  when Hash
26
- obj.transform_values { |v| sort_yaml_keys(v) }
27
- .sort.to_h
26
+ # Single pass: sorted keys once, one rebuilt hash (the
27
+ # transform_values + sort.to_h form rebuilt every container
28
+ # twice).
29
+ sorted = {}
30
+ obj.keys.sort.each { |key| sorted[key] = sort_yaml_keys(obj[key]) }
31
+ sorted
28
32
  when Array
29
33
  obj.map { |item| sort_yaml_keys(item) }
30
34
  else
@@ -134,8 +134,7 @@ module Canon
134
134
  keep: Canon::Xml::WhitespacePolicy.keep_html_text?(
135
135
  node.content,
136
136
  parent_name: node.parent.is_a?(Nokogiri::XML::Element) ? node.parent.name : nil,
137
- inline_significant:
138
- Canon::Comparison::WhitespaceSensitivity.inline_whitespace_significant?(node),
137
+ text_node: node,
139
138
  ),
140
139
  )
141
140
  when Nokogiri::XML::Comment
data/lib/canon/version.rb CHANGED
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Canon
4
- VERSION = "0.3.16"
4
+ VERSION = "0.3.18"
5
5
  end
@@ -61,13 +61,18 @@ element_parent: true)
61
61
  # so it is checked explicitly).
62
62
  HTML_WHITESPACE_SENSITIVE_TAGS = %w[pre code textarea script style].freeze
63
63
 
64
- def keep_html_text?(content, parent_name:, inline_significant: false)
64
+ def keep_html_text?(content, parent_name:, text_node: nil)
65
65
  return true unless content.match?(STRIP_ONLY)
66
66
  return true if content.include?(" ")
67
67
 
68
68
  parent_name = parent_name.to_s.downcase
69
69
  return true if HTML_WHITESPACE_SENSITIVE_TAGS.include?(parent_name)
70
- return true if inline_significant
70
+
71
+ # Computed last: the sibling scan is O(siblings), so it must
72
+ # not run for the content-bearing text nodes that fail the
73
+ # whitespace-only check above.
74
+ return true if text_node &&
75
+ Canon::Comparison::WhitespaceSensitivity.inline_whitespace_significant?(text_node)
71
76
 
72
77
  false
73
78
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: canon
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.16
4
+ version: 0.3.18
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ribose Inc.