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 19:24:02 +0300 Message-ID: <83letbbhzx.fsf@gnu.org> References: <83pmioca3h.fsf@gnu.org> Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="7196"; 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 18:25:15 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 1o7fvm-0001jp-Rt for geb-bug-gnu-emacs@m.gmane-mx.org; Sat, 02 Jul 2022 18:25:15 +0200 Original-Received: from localhost ([::1]:48606 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1o7fvl-0008JC-Rq for geb-bug-gnu-emacs@m.gmane-mx.org; Sat, 02 Jul 2022 12:25:13 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:39036) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1o7fva-0008Ek-0O for bug-gnu-emacs@gnu.org; Sat, 02 Jul 2022 12:25:02 -0400 Original-Received: from debbugs.gnu.org ([209.51.188.43]:48813) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1o7fvZ-0002Ew-Nb for bug-gnu-emacs@gnu.org; Sat, 02 Jul 2022 12:25:01 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1o7fvZ-0003fk-II for bug-gnu-emacs@gnu.org; Sat, 02 Jul 2022 12:25:01 -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 16:25:01 +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.165677906014060 (code B ref 56347); Sat, 02 Jul 2022 16:25:01 +0000 Original-Received: (at 56347) by debbugs.gnu.org; 2 Jul 2022 16:24:20 +0000 Original-Received: from localhost ([127.0.0.1]:42710 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1o7fuu-0003ei-Iw for submit@debbugs.gnu.org; Sat, 02 Jul 2022 12:24:20 -0400 Original-Received: from eggs.gnu.org ([209.51.188.92]:53830) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1o7fus-0003eV-SY for 56347@debbugs.gnu.org; Sat, 02 Jul 2022 12:24:19 -0400 Original-Received: from fencepost.gnu.org ([2001:470:142:3::e]:50232) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1o7fun-00027V-Fw; Sat, 02 Jul 2022 12:24:13 -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=fbtb3YCY6GHoMMdP3peHXkuLS+DCwieDNvxi7hfYvyA=; b=lVhLsqcITPCA QgBlZ+HkoBckt1mezvTUa1fMg4aeN5QxK0CgPUAZNxiRcs5IA7D1sxlZe14ntwLk2dpGBKQvmKXf5 FW/gptBEsW2YGmnQ6X5HWZvf9ewiIEchAz4F2F8qjNyU5kvbjRsQNbn+XvKZBt8Pn2rBBqyC9DcKA PBV+6Ga4C3fJuyV5IfV1U4zM8QtgtSnpFQiVglWFHt9AkwR6LkR0J1zHKeIAFm7GrzZ6m/TR0Idx9 p2GnCgee3LiBhdwdu4QDLpW2Q7ezWcmZQR37AvSFGSCglp2UeEDVpYz+LtNvNvZFRQblHJxWTjJhJ O7tmgqBlVBQhStuXV0bo0A==; Original-Received: from [87.69.77.57] (port=2699 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 1o7fum-00078m-WC; Sat, 02 Jul 2022 12:24:13 -0400 In-Reply-To: (message from Stefan Monnier on Sat, 02 Jul 2022 12:12:06 -0400) 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:235931 Archived-At: > From: Stefan Monnier > Cc: 56347@debbugs.gnu.org > Date: Sat, 02 Jul 2022 12:12:06 -0400 > > STRING_SET_MULTIBYTE is fundamentally evil because it changes the nature > of an object. Its current definition (like that of STRING_SET_UNIBYTE) > is rather scary (it sometimes changes the nature of the arg passed to > it, and sometimes replaces the arg with something else). But do we have any alternatives? > >> - /* 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? > > I don't even know how to go about doing that, no. Make a character-composition rule that composes, say, two '-' characters, and then display a buffer where you have adjacent dashes. > > 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. > > [ I assume you meant "barfs if we keep a *uni*byte string here". ] Yes. > Where? I don't remember, sorry. > >> -#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? > > No, I want to reduce the scope of semantics of the macro, e.g. so it can > be implemented as a function rather than a macro and so it doesn't > magically substitute empty_multibyte_string into a variable that held > something else. But the effect is that you disallow calling STRING_SET_MULTIBYTE on an empty string, isn't it?