canon 0.3.19 → 0.3.20

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: b04c8b44b470bb85f2ec003f434a0fa8ede8eec74f687b388241814e60841415
4
- data.tar.gz: a944aa18b2dd0993362d15a92cf70488a0618841445873c617c206a5e6fe4f72
3
+ metadata.gz: 581a483d81eba304f20fefc4e14777efced86bd7b829d1181209bee00c3ac7df
4
+ data.tar.gz: ea8929a3686f268e5c99376a0aded4999714b298fe7a558c2ac713929fe3d6ac
5
5
  SHA512:
6
- metadata.gz: dfc4366fc597d9a8c33201cf7ed4857f3577e791d0fc80160c0e6dbeda359f5c7ea0d8df49f4dcec22ffe7c596e1a694ec114b8005bce7275f9e6572b3643f77
7
- data.tar.gz: 3b00f6d66f7c75e3f4dccb224347b3092ea4713aa44906c1bc623b3fee6086f940d9c13b5af10c8c60f063d8e16e82a99adc412e662cb4fe092bb23f8129c1b4
6
+ metadata.gz: 19d37bd2c6fec3949791787ca2a64e24afce11588bf17d335efa81fba225d945d77e578a2eb8dae0b8df48904f0f824830f43018cd78830448e05da127498f99
7
+ data.tar.gz: d3c3f990c6a133cb9cada5dbfae4bb752f524c972f3b75253c24c71226e7ad86138467559e533611b20beb95520f4441bfb80fafd4648bacf5b63e0717a69e70
data/lib/canon/cache.rb CHANGED
@@ -44,7 +44,8 @@ module Canon
44
44
  cache.delete(oldest_key) if oldest_key
45
45
  end
46
46
 
47
- cache[key] = { value: value, accessed: Time.now }
47
+ @clock = (@clock || 0) + 1
48
+ cache[key] = { value: value, accessed: @clock }
48
49
  value
49
50
  end
50
51
 
@@ -77,12 +78,6 @@ module Canon
77
78
  "doc:#{format}:#{preprocessing}:#{content_hash(content)}"
78
79
  end
79
80
 
80
- # Generate cache key for format detection
81
- def key_for_format_detection(content)
82
- preview = content[0..100].b
83
- "fmt:#{content_hash(preview + content.length.to_s)}"
84
- end
85
-
86
81
  # Generate cache key for XML canonicalization
87
82
  def key_for_c14n(content, with_comments)
88
83
  "c14n:#{with_comments}:#{content_hash(content)}"
@@ -53,15 +53,16 @@ module Canon
53
53
  raise Canon::Error, "Unknown format for object: #{obj.class}"
54
54
  end
55
55
 
56
- # Detect the format of a string with caching
56
+ # Detect the format of a string
57
57
  #
58
58
  # @param str [String] String to detect format of
59
59
  # @return [Symbol] Format type
60
60
  def detect_string(str)
61
- # Use cache for format detection
62
- Cache.fetch(:format_detect, Cache.key_for_format_detection(str)) do # rubocop:disable Lint/UselessDefaultValueArgument
63
- detect_string_uncached(str)
64
- end
61
+ # Detection is a handful of prefix checks and one anchored
62
+ # regex building the SHA256 cache key (plus LRU clock
63
+ # bookkeeping) cost several times the detection itself, so
64
+ # the answer is computed directly.
65
+ detect_string_uncached(str)
65
66
  end
66
67
 
67
68
  # Detect the format of a string without caching
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.19"
4
+ VERSION = "0.3.20"
5
5
  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.19
4
+ version: 0.3.20
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ribose Inc.