From f8e672423fa08f00e1ccfbabe19d3aebeb6958e0 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Mattias=20Engdeg=C3=A5rd?= Date: Sun, 12 May 2024 15:18:19 +0200 Subject: [PATCH] Revert "Avoid resizing mutation in subst-char-in-string" This reverts commit 184d6e8c02345583264b053bb59ae031bb1c5a00. It wasn't quite correct: the path through `string-replace` would not preserve text properties in the input string, which broke Gnus. (cherry picked from commit 9d7b22fcb408b3d864d4d74d14ab428a2706b45d) --- lisp/subr.el | 20 +++++++------------- 1 file changed, 7 insertions(+), 13 deletions(-) diff --git a/lisp/subr.el b/lisp/subr.el index 9abcecd7c04..de5d5c72911 100644 --- a/lisp/subr.el +++ b/lisp/subr.el @@ -5694,19 +5694,13 @@ The SEPARATOR regexp defaults to \"\\s-+\"." (defun subst-char-in-string (fromchar tochar string &optional inplace) "Replace FROMCHAR with TOCHAR in STRING each time it occurs. Unless optional argument INPLACE is non-nil, return a new string." - (if (and (not inplace) - (if (multibyte-string-p string) - (> (max fromchar tochar) 127) - (> tochar 255))) - ;; Avoid quadratic behaviour from resizing replacement. - (string-replace (string fromchar) (string tochar) string) - (let ((i (length string)) - (newstr (if inplace string (copy-sequence string)))) - (while (> i 0) - (setq i (1- i)) - (if (eq (aref newstr i) fromchar) - (aset newstr i tochar))) - newstr))) + (let ((i (length string)) + (newstr (if inplace string (copy-sequence string)))) + (while (> i 0) + (setq i (1- i)) + (if (eq (aref newstr i) fromchar) + (aset newstr i tochar))) + newstr)) (defun string-replace (from-string to-string in-string) "Replace FROM-STRING with TO-STRING in IN-STRING each time it occurs." -- 2.39.5