[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: master 49e243c0c85: Avoid resizing mutation in subst-char-in-string,
From: |
Mattias Engdegård |
Subject: |
Re: master 49e243c0c85: Avoid resizing mutation in subst-char-in-string, take two |
Date: |
Mon, 13 May 2024 21:20:24 +0200 |
13 maj 2024 kl. 19.53 skrev Eli Zaretskii <eliz@gnu.org>:
>
>> + (if (and (not inplace)
>> + (if (multibyte-string-p string)
>> + (> (max fromchar tochar) 127)
>> + (> tochar 255)))
>
> Is the above condition correct? My reading of it is that if INPLACE
> is non-nil, we use aset (which will resize a string) even if TOCHAR
> needs more bytes than FROMCHAR. Which seems to be in contradiction
> with the goal of the change, as advertised by the log message: "avoid
> resizing mutation".
I agree that it does look a bit odd, but it's intentional. First of all, the
aim is to insulate non-mutating calls to the function from issues arising from
mutation in the implementation. If we don't have to mutate and it's faster
and/or safer not to, then we shouldn't.
Second, the function is documented to change the string in-place if INPLACE is
non-nil, so in that case we have no choice but to mutate, or we might silently
break reasonable code.
> why, in the case of a multibyte STRING, does the code look at the
> codepoints of FROMCHAR and TOCHAR and not at the number of bytes they
> take in the internal Emacs representation of the characters?
It's a conservative approximation that is much simpler than computing the size
of the internal representation. (It's also the condition proposed in bug#70784.)
- Re: master 49e243c0c85: Avoid resizing mutation in subst-char-in-string, take two, Eli Zaretskii, 2024/05/13
- Re: master 49e243c0c85: Avoid resizing mutation in subst-char-in-string, take two,
Mattias Engdegård <=
- Re: master 49e243c0c85: Avoid resizing mutation in subst-char-in-string, take two, Eli Zaretskii, 2024/05/14
- Re: master 49e243c0c85: Avoid resizing mutation in subst-char-in-string, take two, Mattias Engdegård, 2024/05/14
- Re: master 49e243c0c85: Avoid resizing mutation in subst-char-in-string, take two, Eli Zaretskii, 2024/05/14
- Re: master 49e243c0c85: Avoid resizing mutation in subst-char-in-string, take two, Mattias Engdegård, 2024/05/15
- Re: master 49e243c0c85: Avoid resizing mutation in subst-char-in-string, take two, Eli Zaretskii, 2024/05/15
- Re: master 49e243c0c85: Avoid resizing mutation in subst-char-in-string, take two, Mattias Engdegård, 2024/05/15
- Re: master 49e243c0c85: Avoid resizing mutation in subst-char-in-string, take two, Eli Zaretskii, 2024/05/15
- Re: master 49e243c0c85: Avoid resizing mutation in subst-char-in-string, take two, Mattias Engdegård, 2024/05/15