mirror of
https://github.com/brues-code/ClassicAPI.git
synced 2026-11-16 08:00:42 +00:00
The heal's fallback walked down from the stale stored length one rawgeti per slot — O(stale gap) — and since a length read never writes back, it did so on EVERY luaL_getn read until the next append re-synced the length. A table cleared by `pairs` and then polled through getn / concat / sort / unpack paid the full walk each time. The search is now the doubling-then-bisect that luaH_getn uses for 5.1's `#`, in one shared header (table/Border.h) that both `__len` and the heal call; the copy that lived in Transpile.cpp is gone. The mark gate is unchanged in meaning: `n - b == 1` said "slot n-1 is populated", so it is now that one probe, tested before the registry lookup. For a fully cleared table and a table stale by one the answer is identical; a stale table with holes gets some border rather than the highest one, which is what 5.1 itself returns for that table. Verified in game: the reserved slot with a hole present (5, "c"), the stale-by-one recycle (7, 2), the full clear (9, 1), 1,000 getn reads on a cleared 20,000-slot table with no hitch, and `#` through the shared search.