Subject: Re: bug#77942: 31.0.50; replace-region-contents gets stuck

From: Stefan Monnier <[email-masked]>
Date: Tue, 22 Apr 2025 09:26:25 -0400

Gerd Möllmann [2025-04-22 05:48:14] wrote:
> Stefan Monnier <[email-masked]> writes:
>> Gerd, IIUC you're trying to use this to benchmark the charpos->bytepos
>> code, in which case you should be better served by a call where the text
>> and its replacement are of fairly similar size.
>
> That's right, it's for a bencnmark that helps me to get an impression if
> avoiding the binary search in the charpos -> bytepos case is worth it.
> Now that I know what replace-region-contents does, that's no problem.
>
> But honestly, what the heck? Does someone know what this diffing is
> about in the first place? I mean, that replacing a region takes O(ND) is
> not something that I would have thought possible. 

That's why I wanted (well, still want) to have a `replace-region` that
does just the plain/stupid/naive replacement, and then keep
`replace-region-contents` as a separate function (ideally even renamed
to something like `replace-region-slowly` or
`replace-region-carefully`).

One place where the diff's extra work is worthwhile is when you do
reindent/prettyprint via an external process.

        Stefan