Subject: bug#76538: 31.0.50; 31.0.50; 31.0.50; feature/igc: using magit-section-cycle-global (S-TAB) and magit-section-toggle (TAB) in some random ways blocks GNU Emacs.

From: Stefan Monnier <[email-masked]>
Date: Fri, 28 Feb 2025 10:22:38 -0500

> How about not relying on buffer markers too much for this job?  And in
> particular, not adding any ephemeral markers when we don't find a
> close-enough existing marker?  We could instead build our own data
> structure, and make it so we could use efficient search methods.

FWIW, my sorted-array-with-gap is kind of trying that, after making the
choice that the cache is eagerly updated during insertion/deletion.
But admittedly, we could keep the markers as they are and use the
sorted-array-with-gap only for the cache.  This way `save-excursion`
would remain as efficient as before.  At the cost of extra code,
of course.

Another attractive choice would be a cache that is flushed during
insertion/deletions (like the cache in `syntax-ppss`).  In that case it
can be a simple growable array with a constant lookup time since we just
look at `cache[POS / N]` where N is some arbitrary factor we choose
based on a tradeoff of size of the cache vs time to scan the bytes from
the cache's info to the actual POS.

        Stefan