Commit Graph
35 Commits
Author SHA1 Message Date
Behdad Esfahbod b98ffb1fbd [cache] Reject out-of-range keys on reads (#6419)
* [cache] Reject out-of-range keys on reads

An empty entry can match an out-of-range key when the packed cache
entry leaves storage bits unused. In the 256-entry binary coverage
cache this reports glyph IDs 32512-32767 as NOT_COVERED, skipping
Context/ChainContext format 2 substitutions and positioning.

Apply the same key range check in get() as set(). Add regression
coverage for spare-bit and full-width entries across all three
storage sizes, with and without atomics.

The new cache test fails before the fix and passes afterward, also
with HB_TINY. All 28 GSUB/GPOS Context/ChainContext boundary cases
pass. meson test -C build: 272 passed, 1 skipped, 0 failed.

Fixes: https://github.com/harfbuzz/harfbuzz/issues/6418
Assisted-by: OpenAI Codex

* [cache] Combine cache miss checks into one branch

Fold the key range check into the existing miss condition using
bitwise operations. XOR the stored and queried tags so their
mismatch can be combined directly with key overflow and the empty
entry check.

Use a scalar empty-entry constant rather than casting through
item_t, which creates temporary atomic objects in GCC builds.
The binary, mapping, and cmap lookup probes now each have one
conditional branch with GCC 15 and Clang 21 at -O2 on x86-64,
compared with two or three in the initial fix.

Testing: meson test -C build: 272 passed, 1 skipped, 0 failed.
All 28 GSUB/GPOS Context/ChainContext boundary cases pass. The cache
regression also passes with Clang and with HB_TINY.

Assisted-by: OpenAI Codex
2026-10-19 19:16:51 -06:00
Behdad Esfahbod 2994c4d0a6 [Coverage] Fix cache behavior with out-of-range keys (#6321)
Ouch!

Fixes https://github.com/harfbuzz/harfbuzz/issues/6320
2026-10-05 12:42:27 -06:00
Behdad Esfahbod d15bc8d4e9 [contextual] Use a binary coverage cache (in format2)
Reduces cache size by half.

Since we discard the actual coverage number anyway.
2025-12-20 17:08:48 -07:00
Behdad Esfahbod b98ec96008 [cache] Fix get() check for item_t=int16_t
Fixes https://github.com/harfbuzz/harfbuzz/issues/5616
2025-10-18 15:00:45 -06:00
Behdad Esfahbod 4aa7dcba0e [Coverage cache] Micro-optimize 2025-08-12 03:18:38 -06:00
Behdad Esfahbod a4dbb7d459 [Coverage] Cache NOT_COVERED effectively (#5453)
Before, our cache.set was always failing for NOT_COVERED,
making the cache ineffective for uncovered glyphs. Fix that.

Some nice speedups in Latin fonts.
2025-08-12 02:34:49 -06:00
Behdad Esfahbod 56f888cea1 [cache] Mark get/set as hot 2025-07-20 07:19:23 -06:00
Behdad Esfahbod 4214bfef55 [cache] Simplify return 2025-07-20 07:19:23 -06:00
Behdad Esfahbod 89ab5f2b21 [cache] Comments 2025-04-01 17:48:08 -06:00
Behdad Esfahbod 48e7e5a008 [cache] Document 2025-04-01 17:43:35 -06:00
Behdad Esfahbod a0d76c5b37 [atomic] Templatize 2025-03-12 17:16:55 -06:00
Behdad Esfahbod 7aba1e6dd2 [cache] Minor use a range for loop 2023-06-29 12:44:34 -06:00
Behdad Esfahbod afae537c3c [cache] Minor remove .init()
Use constructor.
2023-06-29 12:42:44 -06:00
Behdad Esfahbod b31684dca4 [cache] Add some AI-generated comments 2023-04-22 09:47:58 -06:00
Behdad Esfahbod a924bbcfce [atomic/cache] Add hb_atomic_short_t 2023-01-30 14:52:22 -07:00
Behdad Esfahbod 1b53ed3c41 [cache] Remove empty fini() 2023-01-28 13:38:07 -07:00
Behdad Esfahbod 115d572571 [cache] Add constructor 2023-01-28 13:38:07 -07:00
Behdad Esfahbod 9855b678f2 [cache] Minor rewrite assertion 2022-11-16 13:37:34 -07:00
Behdad Esfahbod d7adc55e18 [ot-font] Allow 24bit glyphs in advance cache 2022-08-04 11:40:54 -06:00
Behdad Esfahbod 99070a734a [cache] Use short instead of int if fits 2022-08-04 11:40:54 -06:00
Behdad Esfahbod b78546b1d2 [cache] Residual 2022-08-03 13:02:18 -06:00
Behdad Esfahbod ec90d1e161 [cache] Add a non-threadsafe version
Use in hb-ft, since already mutex'ed.
2022-08-03 13:01:04 -06:00
Behdad Esfahbod f73c15ca6c [atomic-int] Add operators for relaxed ops 2022-08-03 13:01:04 -06:00
Behdad Esfahbod 0bb4c1f021 [cache] Set default values for cache template parameters 2022-05-29 10:23:19 -06:00
Behdad Esfahbod bb48bf52a4 Rename misc uses of "free"
In preparation for fixing https://github.com/harfbuzz/harfbuzz/issues/3044
2021-07-08 10:54:09 -07:00
Ebrahim Byagowi e412008599 Remove redundant void from C++ sources (#1486) 2018-12-17 13:01:01 -05:00
Ebrahim Byagowi b2ebaa9afa Remove redundant 'inline' from methods (#1483) 2018-12-16 14:08:10 -05:00
Behdad Esfahbod 3426a36157 Unbreak bots 2018-10-01 12:55:57 +02:00
Behdad Esfahbod df827a6ab8 [cache] Fix cache coherency corner-case
If key_bits+value_bits-cache_bits==32 then -1 is ambiguous...
2018-10-01 11:39:29 +02:00
Behdad Esfahbod 305468708d [cache] Use atomic writes in clear()
To help TSan.
2018-09-27 16:54:23 -04:00
Behdad Esfahbod 606bf57430 Revert forcing use of single-parameter static_assert()
Some clang versions define static_assert as a macro apparently, so we cannot
redefine it...

This reverts commit 94bfea0ce6.
This reverts commit 4e62627831.
2018-09-16 19:34:39 +02:00
Behdad Esfahbod 4e62627831 Enforce single-param static_assert() only
So we don't accidentally break it again.
2018-09-16 18:09:36 +02:00
Behdad Esfahbod 54998befc4 [ft] Cache advances
I decided to always use the cache, instead of my previous sketch direction
that was to only allocate and use cache if fast advances are not available.
The cache is a mere 1kb, so just use it...

TODO: Invalidate cache on font size change.

Fixes https://github.com/harfbuzz/harfbuzz/issues/651
Fixes https://github.com/harfbuzz/harfbuzz/pull/1082
2018-09-11 14:36:14 +02:00
Behdad Esfahbod 0ea42e117b [cache] Minor 2018-09-11 12:22:42 +02:00
Behdad Esfahbod 0f520adaac Revert "Remove unused hb_cache_t"
This reverts commit 473b17af4d.

Updates to recent changes.
2018-09-11 12:07:39 +02:00