mirror of
https://github.com/shadowsocks/shadowsocks-libev.git
synced 2026-10-20 13:03:50 +00:00
cache.cpp keeps its C API but replaces uthash and the two mallocs per entry with one slab of nodes holding their keys inline, linked in last-use order, and an open-addressing index of node ids that hashes through the slab with a per-cache random seed. Both blocks are reserved by cache_create() and touched only as entries are used, so a large, mostly empty cache costs no resident memory. Semantics are unchanged: an insert evicts the least recently used entry once the cache holds capacity entries (the AEAD-2022 session table's 4095/4096 boundary), lookups refresh recency and age, cache_clear() drops stale entries, and free_cb may re-enter the cache. Re-inserting a key now replaces its data instead of shadowing it. cache_create_keyed() sizes keys per cache; the AEAD-2022 salt pool and session table use it. test_cache_cpp covers the boundary, ordering, replacement, ageing, re-entrant callbacks and limits; alloc_steady_cache requires zero allocations across 100,000 inserts on a full cache. AEAD-2022 ss-server drops from 84 to 80 allocations per relayed connection.