From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!.POSTED!not-for-mail From: Stefan Monnier Newsgroups: gmane.emacs.help Subject: Re: Why does using aset sometimes output raw bytes? Date: Sun, 09 Dec 2018 14:20:07 -0500 Message-ID: References: <87h8fmohmo.fsf@gmx.net> <871s6qobvm.fsf@gmx.net> NNTP-Posting-Host: blaine.gmane.org Mime-Version: 1.0 Content-Type: text/plain X-Trace: blaine.gmane.org 1544383132 13401 195.159.176.226 (9 Dec 2018 19:18:52 GMT) X-Complaints-To: usenet@blaine.gmane.org NNTP-Posting-Date: Sun, 9 Dec 2018 19:18:52 +0000 (UTC) User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/27.0.50 (gnu/linux) To: help-gnu-emacs@gnu.org Original-X-From: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Sun Dec 09 20:18:48 2018 Return-path: Envelope-to: geh-help-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 1gW4bF-0003J0-3F for geh-help-gnu-emacs@m.gmane.org; Sun, 09 Dec 2018 20:18:45 +0100 Original-Received: from localhost ([::1]:56356 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gW4dL-00066P-Mo for geh-help-gnu-emacs@m.gmane.org; Sun, 09 Dec 2018 14:20:55 -0500 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:58049) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gW4cm-00064t-SE for help-gnu-emacs@gnu.org; Sun, 09 Dec 2018 14:20:21 -0500 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gW4cj-0005CU-Mx for help-gnu-emacs@gnu.org; Sun, 09 Dec 2018 14:20:20 -0500 Original-Received: from [195.159.176.226] (port=39251 helo=blaine.gmane.org) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1gW4cj-0005AD-F8 for help-gnu-emacs@gnu.org; Sun, 09 Dec 2018 14:20:17 -0500 Original-Received: from list by blaine.gmane.org with local (Exim 4.84_2) (envelope-from ) id 1gW4aY-0002Vj-Ei for help-gnu-emacs@gnu.org; Sun, 09 Dec 2018 20:18:02 +0100 X-Injected-Via-Gmane: http://gmane.org/ Original-Lines: 28 Original-X-Complaints-To: usenet@blaine.gmane.org Cancel-Lock: sha1:MZO4NDbcyxSp2w1LwI8Up9rmJls= X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 195.159.176.226 X-BeenThere: help-gnu-emacs@gnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: Users list for the GNU Emacs text editor List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Original-Sender: "help-gnu-emacs" Xref: news.gmane.org gmane.emacs.help:118949 Archived-At: > I don't have a use case where using aset like this is indispensable, I > was just experimenting. Are your reservations because the > implementation of aset is brittle, leading to things like the > observations I reported -- maybe too hard to fix and not worth the > trouble? It's not the implementation, but the semantics of unibyte/multibyte strings presumes that the difference doesn't matter much for ASCII-only strings, which is mostly true but isn't true in the case of `aset`. Also you probably expect `aset` to be constant-time, but on multibyte strings it can take time O(N) where N is the length of the string: Emacs's multibyte strings are designed for sequential access rather than random access, and since chars can take a variable amount of space, replacing one with another can require shifting things around and allocating a new chunk of memory. > Or are there other reasons not to use aset as above? In most cases `aset` results in more complex and more brittle code when working on strings. It's not always the case and the code without `aset` occasionally is a lot worse, admittedly, but as a first rule, I strongly recommend to stay away with it. You'll also gain karma points along the way, Stefan