fontist 3.0.27 → 3.0.28

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: 4bca0e4898879c116eb90bccf581f82177caafe4b981ac97d2ed974dbb9c19d2
4
- data.tar.gz: 409088146ecdb388d8efd008f0b7d1d908863fb8d27b6d58aa5371812f5b93bb
3
+ metadata.gz: cdbd031efa6ca583a610246930ceddc3cc365f3b6047d49ccc9287efee8223ec
4
+ data.tar.gz: a5bc28594e55dc5e7a2050293338d9f19597edc44801dfe3bb5c98b9adb900ea
5
5
  SHA512:
6
- metadata.gz: 49bbea30d8a19d69ad796f7dd7fe49c7c6bf940d38a9aeef07aae568f7700cb1b4a9d39e1427f1002dca02837ed41768975fdc6e9baa37d8a4921235a6a6071d
7
- data.tar.gz: adc3b7fe62335de562352d1c516d0c9c71298bf0b5c5764ab2ae8bd64fc921dc55814602e78e40440c6c916e15a3b0ca6649af8ba5f9b88f1ff672ed31f95be3
6
+ metadata.gz: 2d7ec1b13570f62ebe344a5b0e11d18b13e4160ed1e76f4ccbdf93fe3f5d40d376b4af457ee5e5e3f658afbe6c9df9a144a0f011f98cbc2eb39163c15f77f014
7
+ data.tar.gz: 8ebaacfb87497c01fbc41c9074e4febbca0f788f7d81ab6c1d409ae0b7123cdc9d78dbd24501fb03cfa824dcc4932cb10d64f203039185582456a0a466e00410
@@ -75,6 +75,7 @@ module Fontist
75
75
  # Drop the memoized parsed instance along with the index file,
76
76
  # to force a fresh parse on next access
77
77
  Fontist::FromFileCache.clear
78
+ reset_sidecar_cache
78
79
 
79
80
  # Delete the index file and its lookup sidecar to force a
80
81
  # rebuild on next access. This is important for tests to
@@ -96,10 +97,12 @@ module Fontist
96
97
  def sidecar_entries
97
98
  sidecar_path = "#{path}.json"
98
99
  return unless File.exist?(sidecar_path)
99
- return if File.exist?(path) &&
100
- File.mtime(sidecar_path) < File.mtime(path)
100
+ return if sidecar_stale?(sidecar_path)
101
101
 
102
- JSON.parse(File.read(sidecar_path))["entries"]
102
+ entries = cached_sidecar_entries(sidecar_path)
103
+ return entries if entries
104
+
105
+ parse_sidecar_entries(sidecar_path)
103
106
  rescue JSON::ParserError, TypeError
104
107
  nil
105
108
  end
@@ -109,6 +112,51 @@ module Fontist
109
112
  File.write("#{path}.json", JSON.dump("entries" => entries_hash))
110
113
  entries_hash
111
114
  end
115
+
116
+ private
117
+
118
+ def sidecar_stale?(sidecar_path)
119
+ File.exist?(path) && File.mtime(sidecar_path) < File.mtime(path)
120
+ end
121
+
122
+ def cached_sidecar_entries(sidecar_path)
123
+ mtime = File.mtime(sidecar_path)
124
+ entry = nil
125
+ sidecar_cache_mutex.synchronize do
126
+ entry = sidecar_cache[sidecar_path]
127
+ end
128
+ entry[:entries] if entry&.fetch(:mtime, nil) == mtime
129
+ end
130
+
131
+ # Parsing the sidecar costs tens of milliseconds per call and
132
+ # lookups re-enter many times per operation (every printed font
133
+ # path consults the filename sidecar), so parsed entries are
134
+ # memoized per sidecar mtime and shared between callers; treat
135
+ # as read-only
136
+ def parse_sidecar_entries(sidecar_path)
137
+ mtime = File.mtime(sidecar_path)
138
+ entries = JSON.parse(File.read(sidecar_path))["entries"]
139
+
140
+ sidecar_cache_mutex.synchronize do
141
+ sidecar_cache[sidecar_path] = { mtime: mtime, entries: entries }
142
+ end
143
+
144
+ entries
145
+ end
146
+
147
+ # Class-level cache of parsed sidecar entries, invalidated by
148
+ # sidecar mtime so `fontist update` rewrites are picked up
149
+ def sidecar_cache
150
+ @sidecar_cache ||= {}
151
+ end
152
+
153
+ def sidecar_cache_mutex
154
+ @sidecar_cache_mutex ||= Mutex.new
155
+ end
156
+
157
+ def reset_sidecar_cache
158
+ sidecar_cache_mutex.synchronize { sidecar_cache.clear }
159
+ end
112
160
  end
113
161
 
114
162
  # Build index by loading all formulas from disk.
@@ -1,3 +1,3 @@
1
1
  module Fontist
2
- VERSION = "3.0.27".freeze
2
+ VERSION = "3.0.28".freeze
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: fontist
3
3
  version: !ruby/object:Gem::Version
4
- version: 3.0.27
4
+ version: 3.0.28
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ribose Inc.
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2026-11-02 00:00:00.000000000 Z
11
+ date: 2026-11-03 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: down