From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Stefan Monnier via "Bug reports for GNU Emacs, the Swiss army knife of text editors" Newsgroups: gmane.emacs.bugs Subject: bug#56347: Optimize/simplify STRING_SET_MULTIBYTE Date: Fri, 01 Jul 2022 19:32:05 -0400 Message-ID: Reply-To: Stefan Monnier Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="=-=-=" Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="35362"; mail-complaints-to="usenet@ciao.gmane.io" To: 56347@debbugs.gnu.org Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Sat Jul 02 01:33: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 1o7Q8O-0008zi-Pm for geb-bug-gnu-emacs@m.gmane-mx.org; Sat, 02 Jul 2022 01:33:13 +0200 Original-Received: from localhost ([::1]:38996 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1o7Q8N-000091-5q for geb-bug-gnu-emacs@m.gmane-mx.org; Fri, 01 Jul 2022 19:33:11 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:43114) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1o7Q8E-00008r-Vz for bug-gnu-emacs@gnu.org; Fri, 01 Jul 2022 19:33:03 -0400 Original-Received: from debbugs.gnu.org ([209.51.188.43]:45452) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1o7Q8E-0002Cx-AF for bug-gnu-emacs@gnu.org; Fri, 01 Jul 2022 19:33:02 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1o7Q8E-0002V8-5r for bug-gnu-emacs@gnu.org; Fri, 01 Jul 2022 19:33:02 -0400 X-Loop: help-debbugs@gnu.org Resent-From: Stefan Monnier Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Fri, 01 Jul 2022 23:33:01 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: report 56347 X-GNU-PR-Package: emacs X-GNU-PR-Keywords: patch X-Debbugs-Original-To: bug-gnu-emacs@gnu.org Original-Received: via spool by submit@debbugs.gnu.org id=B.16567183519563 (code B ref -1); Fri, 01 Jul 2022 23:33:01 +0000 Original-Received: (at submit) by debbugs.gnu.org; 1 Jul 2022 23:32:31 +0000 Original-Received: from localhost ([127.0.0.1]:39349 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1o7Q7c-0002U5-KR for submit@debbugs.gnu.org; Fri, 01 Jul 2022 19:32:30 -0400 Original-Received: from lists.gnu.org ([209.51.188.17]:36758) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1o7Q7Z-0002Tw-OR for submit@debbugs.gnu.org; Fri, 01 Jul 2022 19:32:23 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:43066) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1o7Q7Z-00005w-Hy for bug-gnu-emacs@gnu.org; Fri, 01 Jul 2022 19:32:21 -0400 Original-Received: from mailscanner.iro.umontreal.ca ([132.204.25.50]:46435) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1o7Q7X-00029A-0T for bug-gnu-emacs@gnu.org; Fri, 01 Jul 2022 19:32:20 -0400 Original-Received: from pmg1.iro.umontreal.ca (localhost.localdomain [127.0.0.1]) by pmg1.iro.umontreal.ca (Proxmox) with ESMTP id D4809100163 for ; Fri, 1 Jul 2022 19:32:16 -0400 (EDT) Original-Received: from mail01.iro.umontreal.ca (unknown [172.31.2.1]) by pmg1.iro.umontreal.ca (Proxmox) with ESMTP id 66E5D10012C for ; Fri, 1 Jul 2022 19:32:15 -0400 (EDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=iro.umontreal.ca; s=mail; t=1656718335; bh=H3mwfhXnXV0oSZCFg+qnpvpQUEXIQ9mI648JQg4lYN8=; h=From:To:Subject:Date:From; b=j8VCWg85pvW3/rqv37hKtQffDnXpoNHSQfp1RM+Ph17w/Vxn9aXtj0aPrD2L1sicR 53Yz/uJHX8uNK6IX97uMzGgnVlb2Ed4PlnsrRDtGuEkALRCuj1EPiQtQ3F5Jr7yxGa W8pvUurkT87Zn55q7XH9/Ngc37a1uSxyghL8ckBbCUHXIOOuQjFUfK7V0bcdwNfJrP wyGTltegNK8xo0snyPFxzrNYigTQlhrjV/piPDaFolnTPkeAAgbiX8zv6HmsI5af0k 5o87ywQpMOmRTt3jIFJhfomTedt1+wOJs738OTFUGdqClbDgC/rI4Ij/Ev+xu7/D6P BzvMeTnLnRldw== Original-Received: from alfajor (unknown [45.72.196.165]) by mail01.iro.umontreal.ca (Postfix) with ESMTPSA id 43F1612013F for ; Fri, 1 Jul 2022 19:32:15 -0400 (EDT) Received-SPF: pass client-ip=132.204.25.50; envelope-from=monnier@iro.umontreal.ca; helo=mailscanner.iro.umontreal.ca X-Spam_score_int: -42 X-Spam_score: -4.3 X-Spam_bar: ---- X-Spam_report: (-4.3 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, RCVD_IN_DNSWL_MED=-2.3, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action 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:235843 Archived-At: --=-=-= Content-Type: text/plain Tags: patch Tags: patch The patch below simplifies code around STRING_SET_MULTIBYTE. Any objection? Stefan In GNU Emacs 29.0.50 (build 1, x86_64-pc-linux-gnux32, GTK+ Version 3.24.34, cairo version 1.16.0) of 2022-06-30 built on alfajor Repository revision: 2c31b0d5b84471e8b1fa5737b37cf4c241aec036 Repository branch: work Windowing system distributor 'The X.Org Foundation', version 11.0.12101003 System Description: Debian GNU/Linux bookworm/sid Configured using: 'configure -C --enable-checking --enable-check-lisp-object-type --with-modules --with-cairo --with-tiff=ifavailable 'CFLAGS=-Wall -g3 -Og -Wno-pointer-sign' PKG_CONFIG_PATH=/home/monnier/lib/pkgconfig' --=-=-= Content-Type: text/patch Content-Disposition: attachment; filename=set-multibyte.patch diff --git a/src/composite.c b/src/composite.c index 4d69702171f..fb0c51821a5 100644 --- 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. */ } frombyte = string_char_to_byte (string, frompos); } diff --git a/src/lisp.h b/src/lisp.h index 7be2e5d38dc..9f2e7785d2f 100644 --- 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. */ --=-=-=--