From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Eli Zaretskii Newsgroups: gmane.emacs.bugs Subject: bug#56347: Optimize/simplify STRING_SET_MULTIBYTE Date: Sat, 02 Jul 2022 09:17:06 +0300 Message-ID: <83pmioca3h.fsf@gnu.org> References: Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="10484"; mail-complaints-to="usenet@ciao.gmane.io" Cc: 56347@debbugs.gnu.org To: Stefan Monnier Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Sat Jul 02 08:18:13 2022 Return-path: Envelope-to: geb-bug-gnu-emacs@m.gmane-mx.org Original-Received: from lists.gnu.org ([209.51.188.17]) by ciao.gmane.io with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1o7WSK-0002X5-43 for geb-bug-gnu-emacs@m.gmane-mx.org; Sat, 02 Jul 2022 08:18:12 +0200 Original-Received: from localhost ([::1]:42826 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1o7WSI-0004l1-Oc for geb-bug-gnu-emacs@m.gmane-mx.org; Sat, 02 Jul 2022 02:18:10 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:37048) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1o7WSA-0004ks-RZ for bug-gnu-emacs@gnu.org; Sat, 02 Jul 2022 02:18:05 -0400 Original-Received: from debbugs.gnu.org ([209.51.188.43]:45667) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1o7WSA-0003yg-Gn for bug-gnu-emacs@gnu.org; Sat, 02 Jul 2022 02:18:02 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1o7WSA-0002zJ-An for bug-gnu-emacs@gnu.org; Sat, 02 Jul 2022 02:18:02 -0400 X-Loop: help-debbugs@gnu.org Resent-From: Eli Zaretskii Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Sat, 02 Jul 2022 06:18:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 56347 X-GNU-PR-Package: emacs X-GNU-PR-Keywords: patch Original-Received: via spool by 56347-submit@debbugs.gnu.org id=B56347.165674262311413 (code B ref 56347); Sat, 02 Jul 2022 06:18:02 +0000 Original-Received: (at 56347) by debbugs.gnu.org; 2 Jul 2022 06:17:03 +0000 Original-Received: from localhost ([127.0.0.1]:39564 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1o7WRD-0002y1-Ge for submit@debbugs.gnu.org; Sat, 02 Jul 2022 02:17:03 -0400 Original-Received: from eggs.gnu.org ([209.51.188.92]:51972) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1o7WRA-0002xS-4U for 56347@debbugs.gnu.org; Sat, 02 Jul 2022 02:17:02 -0400 Original-Received: from fencepost.gnu.org ([2001:470:142:3::e]:44686) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1o7WR4-0003ob-OE; Sat, 02 Jul 2022 02:16:54 -0400 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=gnu.org; s=fencepost-gnu-org; h=References:Subject:In-Reply-To:To:From:Date: mime-version; bh=Cs5hitmAVTEkqDxKokaKJJyIBNQ2zyQIrXVOSXRAbDc=; b=ZkKmpWvrUvmw yDfYksgfdM9vb0eW//Trf1+jZieP93sYEJwBpVdPgv7iQ1yTsyqoO68B6tohIoqCxgCKiXgczx38k KxdtcTZS4nKME05GmWwYGS8GMo8iO3aiSf/b4ggA1Ed9ok8lBpVzKTh6rFjdzDRTkjZnE2x4AEyr2 MgOhkZlQf1KN5KLZwqAQomNnKf5U+guQ8XL4NAP619U1S2udHvN1FksdHKUHI5TiRubXLtbWWlIbB QzFIOiAgK9JxsJvPTJ1j0U2fbqdX9D/YAx5sloSL1dl5LONxxPzPEDpggqSrYoMja9TZD4T+qOiQc aTiKHrKuLv/fiRSmCG6jlA==; Original-Received: from [87.69.77.57] (port=4989 helo=home-c4e4a596f7) by fencepost.gnu.org with esmtpsa (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1o7WR4-0002st-8O; Sat, 02 Jul 2022 02:16:54 -0400 In-Reply-To: (bug-gnu-emacs@gnu.org) X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list X-BeenThere: bug-gnu-emacs@gnu.org List-Id: "Bug reports for GNU Emacs, the Swiss army knife of text editors" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Original-Sender: "bug-gnu-emacs" Xref: news.gmane.io gmane.emacs.bugs:235849 Archived-At: > Date: Fri, 01 Jul 2022 19:32:05 -0400 > From: Stefan Monnier via "Bug reports for GNU Emacs, > the Swiss army knife of text editors" > > The patch below simplifies code around STRING_SET_MULTIBYTE. > Any objection? Rationale? Simplification in these cases is minimal, almost non-existent, so it cannot be the only rationale. > --- a/src/composite.c > +++ b/src/composite.c > @@ -1879,11 +1879,7 @@ Otherwise (for terminal display), FONT-OBJECT must be a terminal ID, a > for (i = SBYTES (string) - 1; i >= 0; i--) > if (!ASCII_CHAR_P (SREF (string, i))) > error ("Attempt to shape unibyte text"); > - /* STRING is a pure-ASCII string, so we can convert it (or, > - rather, its copy) to multibyte and use that thereafter. */ > - Lisp_Object string_copy = Fconcat (1, &string); > - STRING_SET_MULTIBYTE (string_copy); > - string = string_copy; > + /* STRING is a pure-ASCII string, so we can treat it as multibyte. */ Did you actually try your change in the situations where this problem pops up? AFAIR, the code makes a copy of the string for good reasons: the rest of handling of the string down the line barfs if we keep a multibyte string here. > --- a/src/lisp.h > +++ b/src/lisp.h > @@ -1637,12 +1637,10 @@ #define STRING_SET_UNIBYTE(STR) \ > > /* Mark STR as a multibyte string. Assure that STR contains only > ASCII characters in advance. */ > -#define STRING_SET_MULTIBYTE(STR) \ > - do { \ > - if (XSTRING (STR)->u.s.size == 0) \ > - (STR) = empty_multibyte_string; \ > - else \ > - XSTRING (STR)->u.s.size_byte = XSTRING (STR)->u.s.size; \ > +#define STRING_SET_MULTIBYTE(STR) \ > + do { \ > + eassert (XSTRING (STR)->u.s.size > 0); \ > + XSTRING (STR)->u.s.size_byte = XSTRING (STR)->u.s.size; \ > } while (false) > > /* Convenience functions for dealing with Lisp strings. */ You want to disallow uses of empty_multibyte_string? why?