all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: David Kastrup <dak@gnu.org>
To: Dmitry Antipov <dmantipov@yandex.ru>
Cc: Stefan Monnier <monnier@IRO.UMontreal.CA>, emacs-devel@gnu.org
Subject: Re: (n)reverse vs. length
Date: Thu, 15 May 2014 07:49:35 +0200	[thread overview]
Message-ID: <8761l7sia8.fsf@fencepost.gnu.org> (raw)
In-Reply-To: <5374429A.3090704@yandex.ru> (Dmitry Antipov's message of "Thu, 15 May 2014 08:29:14 +0400")

Dmitry Antipov <dmantipov@yandex.ru> writes:

> On 05/15/2014 05:45 AM, Stefan Monnier wrote:
>
>>>> strings should be immutable
>>> Doesn't aset work on strings?
>>
>> Yes, I said "should be" not "are".
>
> Hm, what about an existing code which relies on aset'table strings? Questions
> like http://lists.gnu.org/archive/html/emacs-devel/2014-04/msg00378.html shows
> that treating string as an array of characters is a common practice (which is
> "natural" for the people with C background). And, in case of large strings,
> in-place reverse may save a lot of memory.

I am not sure there is a use case for in-place reverse of strings.  If
there is, the algorithm for multibyte characters would definitely
warrant writing in C as it is quite non-trivial.  Two characters of
buffer should suffice: just copy one character from each end to its
respective buffer, and then repeat copying and refilling the respective
one of the two buffers which has enough space to fit in the original
string.  Doing it in C would be O(n), doing it with aset instead would
be O(n^2).

-- 
David Kastrup



  reply	other threads:[~2014-05-15  5:49 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-05-14 14:19 (n)reverse vs. length Dmitry Antipov
2014-05-14 19:10 ` Stefan Monnier
2014-05-14 20:12   ` David Kastrup
2014-05-15  1:45     ` Stefan Monnier
2014-05-15  4:29       ` Dmitry Antipov
2014-05-15  5:49         ` David Kastrup [this message]
2014-05-15 12:38         ` Stefan Monnier

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=8761l7sia8.fsf@fencepost.gnu.org \
    --to=dak@gnu.org \
    --cc=dmantipov@yandex.ru \
    --cc=emacs-devel@gnu.org \
    --cc=monnier@IRO.UMontreal.CA \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this external index

	https://git.savannah.gnu.org/cgit/emacs.git
	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.