mirror of
https://git.savannah.gnu.org/git/coreutils.git
synced 2026-11-17 18:02:09 +03:00
Replace the O(N) scan of watched names on each directory inotify event with a Hash_table keyed by (parent_wd, basename), addressing the long-standing FIXME in tail_forever_inotify. Keep ownership consistent with wd_to_name: parent_by_name is created only for Follow_name and returned to the caller, so fallback paths can return without local hash cleanup. Hash basenames with hash_string() and mix in parent_wd, matching the existing gnulib helper rather than a hand-rolled string hash. Matching cost for N directory events that each compare against N names (illustrative host timings of the scan vs hash lookup alone): N=1000: ~0.018s -> ~0.000s N=5000: ~0.39s -> ~0.000s N=10000: ~1.5s -> ~0.000s End-to-end recreate storms remain largely file-system bound on this host; the hash removes the quadratic name-matching CPU from that path. * src/tail.c (parent_name_hasher, parent_name_comparator): New. (tail_forever_inotify): Build and use parent_by_name; return it to the caller. (main): Free parent_ht when non-NULL. * tests/tail/inotify-parent-hash.sh: Require notification mode; cover multiple names in one directory and the same basename in two directories. * tests/local.mk: Reference the new test. * NEWS: Mention the improvement.