Commit Graph

9 Commits

Author SHA1 Message Date
NRK 20725b0b4d icons-hash: replace assert with handmade version
since 2fc9d51, the hash-table generator inherits environmental
CFLAGS and so we shouldn't disallow setting -DNDEBUG.

fixes: https://github.com/jarun/nnn/issues/1632
2023-04-22 17:08:00 +06:00
NRK fb5b2e5e64 icons-hash: fix bitwise rotation
in case the rotation is 0, `v >> (32 - r)` would end up doing a 32 right
shift which is equal to the width of `v` and thus undefined behavior.

ref: https://blog.regehr.org/archives/1063
2023-01-03 02:20:21 +06:00
N-R-K 2000ed5080
icons-hash: misc improvements (#1553)
* icons-hash: take total probe count into account as well

* icons-hash: use a better PRNG

the older method was using a multiplicative congruential generator (MCG)
which doesn't work too well especially with just 32 bits of state.

change it to a PCG instead with 64 bits of state (and 32 bits of output)
which should give better results.

and since we should get better rng - the search iteration has been
halved as well to save some build time.

* icons-hash: use an xor-rotate hash function

* icons-hash: fix some compiler warnings
2023-01-02 22:23:18 +05:30
NRK e6b6466c49 icons-hash: comments and cleanups
adds some comments, references and cleanups. no change in functionality.
2022-07-25 18:34:36 +06:00
NRK fe9c1bbb3a icons: use a compact array
a lot of the extension use the same icon. this can be exploited via
having an array with all the unique icons and then storing a single byte
index into the unique array.

when using `O_EMOJI` this results in around ~1.7KiB drop in the total
table size. `O_NERD` and `O_ICONS` get roughly ~0.5KiB savings.
2022-07-24 16:24:11 +06:00
NRK 63a254951d icons-hash: some minor cleanups 2022-07-24 16:24:11 +06:00
NRK e98d9288d2 some cleanups and comments 2022-07-22 21:33:35 +06:00
NRK c3a42f0d92 make clang-tidy happy 2022-07-22 17:31:55 +06:00
NRK 3b09fd1c75 Revise and optimize icons handling
This pretty much reworks the entire icon system. Some notable changes:

* The extensions are put into a statically generated hash-table instead
  of a sorted array. We use Robin-Hood insertion to reduce the max probe
  length. Currently we need to probe only 2 slots for `O_EMOJI` and only
  3 for `O_NERD`/`O_ICONS`.
* I've opted not to use a perfect-hash since the perfect hashes
  generated by [`gperf`](https://www.gnu.org/software/gperf) used some
  huge lookup table. The hash function also wasn't as minimal as I'd
  like.
* Colors are now using X-Macros. This should speed up startup since we
  don't have to search `icons_ext` linearly to find unique colors.
* The hash-table generator outputs a more space optimized `struct
  icon_pair` using a char array instead of char pointer. This brings
  down the binary size from `145KiB` when using `O_NERD` down to
  `137KiB`.
* Some unnecessary duplication and indirection has been reduced by using
  the `ICON_STR()` macro.
2022-07-22 17:08:42 +06:00