Subject: bug#70784: Abolish string resizing

From: Po Lu <[email-masked]>
Date: Tue, 07 May 2024 21:41:10 +0800

Eli Zaretskii <[email-masked]> writes:

> What _would_ matter is if there are important use cases out there
> where replacing one character by another character of a different
> multibyte length.  So if you, or anyone else, can come up with such
> situations (which are not made up specifically to argue here), please
> do, because knowing about such situations would be useful to make this
> discussion serious and based on facts.

There is certainly plenty of Emacs code that needs to replace characters
within strings whose contents are more or less arbitrary, so that
whether Mattias's proposal will disrupt them will vary in an
unpredictable manner from one string to the next.  I would venture to
suggest that _every_ invocation of aset with multibyte strings will
potentially be disrupted by the proposal in its mildest form, and it
will only be a matter of time before problems surface.  A wildly
variable length of time, for that matter, so it is infeasible to
anticipate their impact ahead of time, at least with the accuracy that
such a change deserves.

Nevertheless, examples are legion and one need search no further than
one's own init files for them:

      (progn
        [...]
	(if allow_unicode
	    (progn
	      (aset string pac-quote-start ?“)
              (aset string (1- pac-quote-close) ?”)
	      )
	  (progn
	    ;; Sometimes [...] prints unicode quotation marks
	    ;; surrounding pac captions so prevent inserting them into
	    ;; source code comments.
	    (aset string pac-quote-start ?\")
	    (aset string (1- pac-quote-close) ?\")
	    )
	  )
        [...]
	)

string is process output from shell-command-to-string, generated by a
Perl script I cannot publish.  Please don't ask for details as to the
script itself, since I am not at liberty to disclose them, and they have
absolutely no bearing on the matter at hand.