[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: A function to take the regexp-matched subsring directly
From: |
Stefan Monnier |
Subject: |
Re: A function to take the regexp-matched subsring directly |
Date: |
Sun, 30 Oct 2022 18:07:46 -0400 |
User-agent: |
Gnus/5.13 (Gnus v5.13) Emacs/29.0.50 (gnu/linux) |
>> `save-match-data` is costly and extremely rarely needed.
> What makes it so expensive? The implementation appears to be trivial.
It allocates cons cells (by calling `match-data`) to store the values.
If you put it in such a place it will be wasted 99% of the time.
>> So I'd much rather not save it here.
> If the function is supposed to be side-effect-free, then it ought not to
> sometimes replace the match data and not touch it when optimised away.
The match-data is defined to be something very ephemeral, so it's OK for
pure functions to clobber it.
Admittedly, here it doesn't just clobber it but sets it to a reliable
value, so there's a high risk that someone will rely on that match-data,
so better not mark it as pure, indeed, contrary to what I said earlier.
Stefan