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 +4 -4
- data/lib/canon/cache.rb +2 -7
- data/lib/canon/comparison/format_detector.rb +6 -5
- data/lib/canon/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: 581a483d81eba304f20fefc4e14777efced86bd7b829d1181209bee00c3ac7df
|
|
4
|
+
data.tar.gz: ea8929a3686f268e5c99376a0aded4999714b298fe7a558c2ac713929fe3d6ac
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
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
|
-
|
|
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
|
|
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
|
-
#
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
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