emacs-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: string_char_to_byte and string_byte_to_char micro-optimisation


From: Stefan Monnier
Subject: Re: string_char_to_byte and string_byte_to_char micro-optimisation
Date: Sat, 15 Jun 2019 03:48:04 -0400
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/27.0.50 (gnu/linux)

>> ... and uses `aref` on it extensively.
> Right.  And/or 'aset'.

Right, but `aset` is even more rare on multibyte strings.

> Other candidates are 'string-match' and 'replace-match'.

`replace-match` has to copy the string, so charpos<->bytepos conversion
doesn't slow it down significantly (I'd guess it's at most a factor of 2).

`string-match` is only affected by charpos<->bytepos is you use the
`start` argument, and the time to perform the actual regexp search will
usually dwarf the charpos<->bytepos conversion, so I think it can only
be noticeably slowed down by charpos<->bytepos conversion in
"pathological" cases where we `start` in the middle of a longish string
and we immediately find a short match.

In contrast, `aref` never does much more than the charpos<->bytepos
conversion itself.


        Stefan




reply via email to

[Prev in Thread] Current Thread [Next in Thread]