From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!.POSTED!not-for-mail From: Milan =?UTF-8?Q?Stanojevi=C4=87?= Newsgroups: gmane.emacs.bugs Subject: bug#31837: 26.1; replace-buffer-contents doesn't work if buffer has multibyte characters Date: Mon, 18 Jun 2018 16:29:41 -0400 Message-ID: References: <7dm4li5jbmk.fsf@janestreet.com> <83tvq41m9r.fsf@gnu.org> <83sh5krmd1.fsf@gnu.org> NNTP-Posting-Host: blaine.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset="UTF-8" X-Trace: blaine.gmane.org 1529353806 25251 195.159.176.226 (18 Jun 2018 20:30:06 GMT) X-Complaints-To: usenet@blaine.gmane.org NNTP-Posting-Date: Mon, 18 Jun 2018 20:30:06 +0000 (UTC) Cc: 31837@debbugs.gnu.org To: Eli Zaretskii Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Mon Jun 18 22:30:02 2018 Return-path: Envelope-to: geb-bug-gnu-emacs@m.gmane.org Original-Received: from lists.gnu.org ([208.118.235.17]) by blaine.gmane.org with esmtp (Exim 4.84_2) (envelope-from ) id 1fV0mn-0006RU-Fg for geb-bug-gnu-emacs@m.gmane.org; Mon, 18 Jun 2018 22:30:01 +0200 Original-Received: from localhost ([::1]:36811 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fV0ou-00073U-Gt for geb-bug-gnu-emacs@m.gmane.org; Mon, 18 Jun 2018 16:32:12 -0400 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:48555) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fV0oo-00073P-OP for bug-gnu-emacs@gnu.org; Mon, 18 Jun 2018 16:32:07 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1fV0ol-0006QN-K6 for bug-gnu-emacs@gnu.org; Mon, 18 Jun 2018 16:32:06 -0400 Original-Received: from debbugs.gnu.org ([208.118.235.43]:47444) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1fV0ol-0006QH-GK for bug-gnu-emacs@gnu.org; Mon, 18 Jun 2018 16:32:03 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1fV0oj-0000OC-PC for bug-gnu-emacs@gnu.org; Mon, 18 Jun 2018 16:32:02 -0400 X-Loop: help-debbugs@gnu.org Resent-From: Milan =?UTF-8?Q?Stanojevi=C4=87?= Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Mon, 18 Jun 2018 20:32:01 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 31837 X-GNU-PR-Package: emacs X-GNU-PR-Keywords: Original-Received: via spool by 31837-submit@debbugs.gnu.org id=B31837.15293538911458 (code B ref 31837); Mon, 18 Jun 2018 20:32:01 +0000 Original-Received: (at 31837) by debbugs.gnu.org; 18 Jun 2018 20:31:31 +0000 Original-Received: from localhost ([127.0.0.1]:55341 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1fV0oF-0000NS-IJ for submit@debbugs.gnu.org; Mon, 18 Jun 2018 16:31:31 -0400 Original-Received: from mxout1.mail.janestreet.com ([38.105.200.78]:54391) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1fV0oD-0000NC-Ed for 31837@debbugs.gnu.org; Mon, 18 Jun 2018 16:31:29 -0400 X-JS-Received: from [30.32.81.38] (helo=igm-qpr-mailcore1) by mxout1.mail.janestreet.com with esmtps (TLSv1.2:ECDHE-RSA-AES256-GCM-SHA384:256) (Exim 4.90_1) (envelope-from ) id 1fV0o7-00084t-P1 for 31837@debbugs.gnu.org; Mon, 18 Jun 2018 16:31:23 -0400 X-JS-Flow: external X-JS-Received: by igm-qpr-mailcore1 with ocaml/mailcore/main_production (840e4f60ecac) (envelope-from ) id BbKBab-S5RzcA-Xj; 2018-06-18 16:31:23.758618-04:00 X-JS-Scanner-attachment: No attachments X-JS-Scanner-esets: Not scanned (internal mail) Original-Received: from mail-lf0-f70.google.com ([209.85.215.70]) by mxgoog2.mail.janestreet.com with esmtps (TLSv1.2:ECDHE-RSA-AES128-GCM-SHA256:128) (Exim 4.90_1) (envelope-from ) id 1fV0o7-0007XQ-K2 for 31837@debbugs.gnu.org; Mon, 18 Jun 2018 16:31:23 -0400 Original-Received: by mail-lf0-f70.google.com with SMTP id g82-v6so5440161lfg.4 for <31837@debbugs.gnu.org>; Mon, 18 Jun 2018 13:31:23 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=janestreet.com; s=google; h=mime-version:in-reply-to:references:from:date:message-id:subject:to :cc; bh=Y442RY8djKKSkt8DSEAnq/Ku8spyeXiSiRLHhPy7PiE=; b=MtC5qAUlpCtky3Wu2CTjExq5huL47fzoGAwDaBCy6Cc1+wsABNtd4ziVqoTT/2L/eb 3JwqzFeEsQKCDI7OUKL5GXh6vHa31gla2UbSHWOoDu7AE7T5WqZ91xu8u+5k7ZolydcQ 7yzCBZbCNpSjtnaSooEWSG3Jz+QifliCuTNtU= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:in-reply-to:references:from:date :message-id:subject:to:cc; bh=Y442RY8djKKSkt8DSEAnq/Ku8spyeXiSiRLHhPy7PiE=; b=n6pnOQ4WQo0XxDrQpQT1Ju2Qbd/Nz4MqM4jAK6UHQBMsB9APj40UimWAu4LjgD6k2b cDpsqhx0eGqjRKdjioVJUIzu/BldIWy8Ekz5fJ5tGkHl11BUjrd8wYJE7qOqnXJ0Tvu3 FsFwhv5Bli7qC1RIkvOCZ3wKP1ZiETJdBQZCVrJKNPrKQLCeI/l892eMxqAF1anH7x91 pLRbwrlm4diZVyTokfCHyrklqMHpKAe165sC8CF0xqo7ychWIiHw9ZZCag0gBR3QGODN Slu263I50nLWlkb6AOdvwjvm6wIWXzvDR+Ykc8nL6Gt89TJjTyoZRNPKa6YVn1gBSHyq 1xfQ== X-Gm-Message-State: APt69E3ZRMQODqcQfSdg7jQibyQ0MwxO2mpaY7UoWEpcRiZr/W6YYcN1 D3HUPBBSp3Fgd8ixfkmRVWgSM1kq5Px04AwYyjL7offX0BSO7FtxvI0HWFuJ75gwP40tTmMvHwQ A5zFaGi23hSxh8lz+ZzmgZI584PLFBQ== X-Received: by 2002:a2e:419:: with SMTP id 25-v6mr8931415lje.146.1529353822648; Mon, 18 Jun 2018 13:30:22 -0700 (PDT) X-Google-Smtp-Source: ADUXVKLHj3Yz1lfuX1cZl6yCYZnpAnusZNI29XHH57leeSq2365NCbJ0wWbk51l3m9A32Nk2ecQdOJO+F/5YO5iRk+k= X-Received: by 2002:a2e:419:: with SMTP id 25-v6mr8931404lje.146.1529353822445; Mon, 18 Jun 2018 13:30:22 -0700 (PDT) Original-Received: by 2002:a19:e9cf:0:0:0:0:0 with HTTP; Mon, 18 Jun 2018 13:29:41 -0700 (PDT) In-Reply-To: <83sh5krmd1.fsf@gnu.org> X-JS-Exim-Data-Received: 2018-06-18 16:31:23-0400 X-JS-Processed-by: mailcore X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 208.118.235.43 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.org@gnu.org Original-Sender: "bug-gnu-emacs" Xref: news.gmane.org gmane.emacs.bugs:147610 Archived-At: >> But what matters is whether there are actual multibyte characters in >> the buffer > > If a buffer is unibyte, there could be no multibyte characters in it, > by definition. > >> buf_charpos_to_bytepos already shortcircuits if there are none. > > Not before it calls some macros. And it is confusing to call a > conversion function when no conversion is needed, because the > correctness of that can only be established by looking at the called > conversion function. That gets in the way of code reading, IME. Right, I get your point regarding readability but maybe I can clarify what I'm thinking. The question is whether we need to optimize buffer_chars_equal or not. If not, then we can just call buf_charpos_to_bytepos without any other checks, that seems most readable. If we do care about optimizing it, then it is better to check whether the buffer actually contains multibyte characters (I guess with BUF_Z(buf) == BUF_Z_BYTE(buf)) than using enable_multibyte_characters since the the former would catch strictly more cases when we don't need charpos to bytepos conversion. Also, it occurs to me, the check shouldn't be done in buffer_chars_equal, since the same check would be done multiple times for a single character (for every comparison of that character), it should be done once and the result stored in ctx before calling compareseq. Again, I'm not sure this matters at all in practice, all the checks are just a few memory accesses (presumable in the cache) and integer comparisons. Anyway, I could try doing something in the future about this, but the code as it is now is perfectly fine. Thanks again!