metanorma 2.5.23 → 2.5.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: b10fe30704e90dd64f266eccf4924730880bbd373d4edc3abcf14680e9d7bf65
4
- data.tar.gz: e558651f1522eb3f278a97da5c9a3884fe037dc9e67b6d863a3365df097a5eb4
3
+ metadata.gz: 5b7f24f8333462e860db4b5e24a6e92f48da2c2ce8dc53f42d0b91da79ffbd9b
4
+ data.tar.gz: b3496f8ce83f4ccdc72b7f757b12ad2108d938de33764b5a7e6be86426f15ffe
5
5
  SHA512:
6
- metadata.gz: fd160507ec2c4095036e73fc0e59d3fddb3d904c9f3d02d583a19739591184ef6df32fb234952f516498ef0cd7e8da4b757b3f6bb416134f4657dd7e054063b8
7
- data.tar.gz: 3bd440249de25476c58639323a600100832a349d46bb37fcfed5b11c9a6db8495e7a26c95ed2ed5be074f986a8e0a5c2b6a7ba770684bc7532a4b32d727e1903
6
+ metadata.gz: 5bc44aaac9aed93d4f70d7a31e15874f8fc37a13d6e222d5f24d5d36dddd7ba8cb1f60e218c574e4be835c8fc309669c3e51f4f03fa1c346f93dfc6ecc42c27f
7
+ data.tar.gz: de64618a5753ed9cf54632ccc79847dc19f836ad805ec7d04f18389eb358ca246d54b63066cfd5bde11db9a46093c8b8b0f862837291aca40ad9c0be9287f1fa
@@ -416,15 +416,35 @@ module Metanorma
416
416
  # name (geometry_schema.cartesian_point_ISO_10303-42_2025_...), so
417
417
  # the plain name resolves by prefix. Multiple equal-length matches
418
418
  # are ambiguous and refuse, as do differing ids at the same key.
419
+ # Memoized per prefix: the index is immutable once built, and a
420
+ # mega-member's svgmap erefs hit this per stage pass (the linear
421
+ # scan showed up at 24%+ of a 104-style render's wall).
419
422
  def hotspot_prefix_lookup(idx, prefix)
420
- return idx[prefix] if idx[prefix]
423
+ @hotspot_prefix_memo ||= {}
424
+ @hotspot_prefix_memo.fetch(prefix) do
425
+ @hotspot_prefix_memo[prefix] =
426
+ idx[prefix] || prefix_lookup_scan(idx, prefix)
427
+ end
428
+ end
421
429
 
422
- candidates = idx.select { |k, r| r && k.start_with?("#{prefix}_") }
430
+ # Candidate keys sharing the prefix, by binary search over the
431
+ # sorted index keys: keys with the stem prefix are contiguous in
432
+ # sort order, so the slice between the lower bound and the first
433
+ # non-matching key is the entire candidate set.
434
+ def prefix_lookup_scan(idx, prefix)
435
+ stem = "#{prefix}_"
436
+ keys = hotspot_sorted_keys(idx)
437
+ lo = keys.bsearch_index { |k| k >= stem } or return nil
438
+ candidates = keys[lo..].take_while { |k| k.start_with?(stem) }
423
439
  return nil if candidates.empty?
424
440
 
425
- shortest = candidates.min_by { |k, _| k.length }
426
- ties = candidates.count { |k, _| k.length == shortest[0].length }
427
- ties == 1 ? shortest[1] : nil
441
+ shortest = candidates.min_by(&:length)
442
+ ties = candidates.count { |k| k.length == shortest.length }
443
+ ties == 1 ? idx[shortest] : nil
444
+ end
445
+
446
+ def hotspot_sorted_keys(idx)
447
+ @hotspot_sorted_keys ||= idx.keys.select { |k| idx[k] }.sort
428
448
  end
429
449
  end
430
450
  end
@@ -1,3 +1,3 @@
1
1
  module Metanorma
2
- VERSION = "2.5.23".freeze
2
+ VERSION = "2.5.24".freeze
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: metanorma
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.5.23
4
+ version: 2.5.24
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ribose Inc.