fontist 3.0.23 → 3.0.24

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: 437b60367c3601897b3f22af4c3e00a2ffec30d74120df9fff64ad76291b7624
4
- data.tar.gz: 49206f8ffe89f3110c8d97513b4b263d6cfc8c47566bf39283464a46b34b94cd
3
+ metadata.gz: 954fe79bde0fb84cf7b2fcc96b686820a7c2f4fd6ec822abd4067b1c0d8c288e
4
+ data.tar.gz: ac7eb9f594dd5a9be155e2893c4a07bad197743e107a92f16786b45f47000224
5
5
  SHA512:
6
- metadata.gz: b95402fae1199140efe5a00a54ce59207bd15268ee28803a3e830942d812ba3d0d8bedddf800a7ebcea6c736666d8f183f68b1df98a74714137da2ebd1fcae86
7
- data.tar.gz: 42d80c546ae290865441aa1ebaf9ac04278ee99dfaad92863dd61b92fb3594511434957d950fbb6551344708ec06da5cf3812fe06e3009c0a36a92cb473c6cef
6
+ metadata.gz: 9616ce9f46708c5acb1dc4643688f8ab0a43eeb5eafc7ee8259e9d5a110e415c738514cc00739d937b41d05d1b64868256419f3303d32159aeb41f462f260207
7
+ data.tar.gz: ba15c400a1fed88380cd28f8669c7272e6d52cf0dcf4df09f42166cc0b95cf55db36dcf5456bd3704981550308e087b2074f3aaaa9419567e75733ff96099bbf
@@ -122,6 +122,7 @@ module Fontist
122
122
  return if collection.fonts.nil?
123
123
 
124
124
  collection.fonts.delete_if { |f| f.path == path }
125
+ collection.invalidate_lookups!
125
126
  collection.to_file(index_path)
126
127
  end
127
128
 
@@ -209,15 +209,29 @@ module Fontist
209
209
  def create_and_add_entry(key, paths)
210
210
  entry = FormulaKeyToPath.new(key: key, formula_path: paths)
211
211
  entries << entry
212
+ @entries_lookup_id = nil
212
213
  @index_build_cache[key] = entry if @index_build_cache
213
214
  end
214
215
 
216
+ # O(1) key lookup over the entries; rebuilt whenever the entries
217
+ # array identity changes (rebuilds parse fresh instances, and
218
+ # in-place additions drop the cached hash)
219
+ def entries_lookup
220
+ entries_id = Array(entries).object_id
221
+ if @entries_lookup_id != entries_id
222
+ @entries_lookup_id = entries_id
223
+ @entries_lookup = Array(entries)
224
+ .group_by { |entry| normalize_key(entry.key) }
225
+ end
226
+ @entries_lookup
227
+ end
228
+
215
229
  def index_formula(key)
216
230
  Array(entries).detect { |f| normalize_key(f.key) == normalize_key(key) }
217
231
  end
218
232
 
219
233
  def index_formulas(key)
220
- Array(entries).select { |f| normalize_key(f.key) == normalize_key(key) }
234
+ entries_lookup[normalize_key(key)] || []
221
235
  end
222
236
 
223
237
  def relative_formula_path(path)
@@ -209,15 +209,13 @@ module Fontist
209
209
 
210
210
  return nil if current_fonts.nil? || current_fonts.empty?
211
211
 
212
- if style.nil?
213
- found_fonts = current_fonts.select do |file|
214
- file.family_name&.casecmp?(font)
215
- end
216
- else
217
- found_fonts = current_fonts.select do |file|
218
- file.family_name&.casecmp?(font) && file.type&.casecmp?(style)
212
+ bucket = family_lookup(current_fonts)[font.to_s.downcase] || []
213
+ found_fonts =
214
+ if style.nil?
215
+ bucket
216
+ else
217
+ bucket.select { |file| file.type&.casecmp?(style) }
219
218
  end
220
- end
221
219
 
222
220
  # Apply format filtering if specified
223
221
  if format_spec&.has_constraints? && found_fonts
@@ -229,6 +227,25 @@ module Fontist
229
227
  found_fonts.empty? ? nil : found_fonts
230
228
  end
231
229
 
230
+ # Drops the cached family lookup; called when fonts are removed in
231
+ # place (a rebuild replaces the fonts array, which re-keys the
232
+ # lookup by itself)
233
+ def invalidate_lookups!
234
+ @family_lookup_fonts_id = nil
235
+ end
236
+
237
+ # O(1) family-name lookup over the indexed fonts; rebuilt whenever
238
+ # the fonts array identity changes
239
+ def family_lookup(current_fonts)
240
+ fonts_id = Array(current_fonts).object_id
241
+ if @family_lookup_fonts_id != fonts_id
242
+ @family_lookup_fonts_id = fonts_id
243
+ @family_lookup = Array(current_fonts)
244
+ .group_by { |file| file.family_name&.downcase }
245
+ end
246
+ @family_lookup
247
+ end
248
+
232
249
  def index
233
250
  if @read_only_mode && !fonts.nil?
234
251
  return fonts
@@ -1,3 +1,3 @@
1
1
  module Fontist
2
- VERSION = "3.0.23".freeze
2
+ VERSION = "3.0.24".freeze
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: fontist
3
3
  version: !ruby/object:Gem::Version
4
- version: 3.0.23
4
+ version: 3.0.24
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ribose Inc.