GNU bug report logs -
#45178
buffer-hash docstring should explain difference to secure-hash
Previous Next
Reported by: Stefan Kangas <stefan <at> marxist.se>
Date: Fri, 11 Dec 2020 14:42:02 UTC
Severity: minor
Fixed in version 28.1
Done: Stefan Kangas <stefan <at> marxist.se>
Bug is archived. No further changes may be made.
To add a comment to this bug, you must first unarchive it, by sending
a message to control AT debbugs.gnu.org, with unarchive 45178 in the body.
You can then email your comments to 45178 AT debbugs.gnu.org in the normal way.
Toggle the display of automated, internal messages from the tracker.
Report forwarded
to
larsi <at> gnus.org, bug-gnu-emacs <at> gnu.org
:
bug#45178
; Package
emacs
.
(Fri, 11 Dec 2020 14:42:02 GMT)
Full text and
rfc822 format available.
Acknowledgement sent
to
Stefan Kangas <stefan <at> marxist.se>
:
New bug report received and forwarded. Copy sent to
larsi <at> gnus.org, bug-gnu-emacs <at> gnu.org
.
(Fri, 11 Dec 2020 14:42:02 GMT)
Full text and
rfc822 format available.
Message #5 received at submit <at> debbugs.gnu.org (full text, mbox):
Severity: minor
It is not clear to me when I would want to use:
(buffer-hash (current-buffer))
instead of
(secure-hash 'sha1 (current-buffer))
One obvious difference is that secure-hash respects narrowing, while
buffer-hash doesn't. But it's not clear to me why I can't just use
save-restrictions+widen instead. The Elisp manual says: "It should be
somewhat more efficient on larger buffers than ‘secure-hash’ is, and
should not allocate more memory."
First, I think we should add something about this to the docstring of
`buffer-hash'. Perhaps we should also mention it in the `secure-hash'
docstring.
Second, is the difference all that important? If so, perhaps we should
look over our uses of `md5', `sha1' and `secure-hash' in our code-base
to ensure we use the more efficient version where applicable. (For
example in savehist.el and desktop.el.)
Information forwarded
to
bug-gnu-emacs <at> gnu.org
:
bug#45178
; Package
emacs
.
(Fri, 11 Dec 2020 16:01:01 GMT)
Full text and
rfc822 format available.
Message #8 received at 45178 <at> debbugs.gnu.org (full text, mbox):
Stefan Kangas <stefan <at> marxist.se> writes:
> Severity: minor
>
> It is not clear to me when I would want to use:
>
> (buffer-hash (current-buffer))
>
> instead of
>
> (secure-hash 'sha1 (current-buffer))
>
> One obvious difference is that secure-hash respects narrowing, while
> buffer-hash doesn't.
I thought the buffer-hash doc string made the use case pretty clear:
----
This function is useful for comparing two buffers running in the same
Emacs, but is not guaranteed to return the same hash between different
Emacs versions.
----
The only use case for the function is to compare two buffers in the same
running Emacs image. It shouldn't be used for anything else.
> First, I think we should add something about this to the docstring of
> `buffer-hash'. Perhaps we should also mention it in the `secure-hash'
> docstring.
I think that would be pointing people in the wrong direction.
`secure-hash' is the right thing to use in 99% of the cases.
--
(domestic pets only, the antidote for overdose, milk.)
bloggy blog: http://lars.ingebrigtsen.no
Information forwarded
to
bug-gnu-emacs <at> gnu.org
:
bug#45178
; Package
emacs
.
(Fri, 11 Dec 2020 16:41:01 GMT)
Full text and
rfc822 format available.
Message #11 received at 45178 <at> debbugs.gnu.org (full text, mbox):
Lars Ingebrigtsen <larsi <at> gnus.org> writes:
> The only use case for the function is to compare two buffers in the same
> running Emacs image. It shouldn't be used for anything else.
I guess what I don't understand is why I would _ever_ want to use this
function. I mean, why not just compare buffers using `secure-hash'?
Information forwarded
to
bug-gnu-emacs <at> gnu.org
:
bug#45178
; Package
emacs
.
(Fri, 11 Dec 2020 16:50:02 GMT)
Full text and
rfc822 format available.
Message #14 received at 45178 <at> debbugs.gnu.org (full text, mbox):
Stefan Kangas <stefan <at> marxist.se> writes:
> I guess what I don't understand is why I would _ever_ want to use this
> function. I mean, why not just compare buffers using `secure-hash'?
`buffer-hash' is fast, so you can use it to compare the buffer contents
before and after doing things like `indent-sexp' to see whether that
changed anything.
--
(domestic pets only, the antidote for overdose, milk.)
bloggy blog: http://lars.ingebrigtsen.no
Information forwarded
to
bug-gnu-emacs <at> gnu.org
:
bug#45178
; Package
emacs
.
(Fri, 11 Dec 2020 19:20:02 GMT)
Full text and
rfc822 format available.
Message #17 received at 45178 <at> debbugs.gnu.org (full text, mbox):
close 45178 28.1
thanks
Lars Ingebrigtsen <larsi <at> gnus.org> writes:
> Stefan Kangas <stefan <at> marxist.se> writes:
>
>> I guess what I don't understand is why I would _ever_ want to use this
>> function. I mean, why not just compare buffers using `secure-hash'?
>
> `buffer-hash' is fast, so you can use it to compare the buffer contents
> before and after doing things like `indent-sexp' to see whether that
> changed anything.
OK, I've benchmarked this and can confirm it is indeed much faster. So
I updated its docstring on master by copying the explanation from the
manual. I'm therefore closing this bug report.
bug marked as fixed in version 28.1, send any further explanations to
45178 <at> debbugs.gnu.org and Stefan Kangas <stefan <at> marxist.se>
Request was from
Stefan Kangas <stefan <at> marxist.se>
to
control <at> debbugs.gnu.org
.
(Fri, 11 Dec 2020 19:20:04 GMT)
Full text and
rfc822 format available.
Information forwarded
to
bug-gnu-emacs <at> gnu.org
:
bug#45178
; Package
emacs
.
(Sun, 20 Dec 2020 11:48:02 GMT)
Full text and
rfc822 format available.
Message #22 received at 45178 <at> debbugs.gnu.org (full text, mbox):
Lars Ingebrigtsen <larsi <at> gnus.org> writes:
> Stefan Kangas <stefan <at> marxist.se> writes:
>
>> I guess what I don't understand is why I would _ever_ want to use this
>> function. I mean, why not just compare buffers using `secure-hash'?
>
> `buffer-hash' is fast, so you can use it to compare the buffer contents
> before and after doing things like `indent-sexp' to see whether that
> changed anything.
[I get that this is just an example, but in this case wouldn't you use
buffer-modified-tick or buffer-chars-modified-tick instead?]
--
Basil
Information forwarded
to
bug-gnu-emacs <at> gnu.org
:
bug#45178
; Package
emacs
.
(Sun, 20 Dec 2020 16:32:01 GMT)
Full text and
rfc822 format available.
Message #25 received at 45178 <at> debbugs.gnu.org (full text, mbox):
"Basil L. Contovounesios" <contovob <at> tcd.ie> writes:
> Lars Ingebrigtsen <larsi <at> gnus.org> writes:
>
>> `buffer-hash' is fast, so you can use it to compare the buffer contents
>> before and after doing things like `indent-sexp' to see whether that
>> changed anything.
>
> [I get that this is just an example, but in this case wouldn't you use
> buffer-modified-tick or buffer-chars-modified-tick instead?]
AFAIU, this is used to detect when a command changed a buffer but the
buffer still is the same before and after the changes. In that case, we
don't want it to be marked as changed even if there were changes taking
place in the background. For example, see `fill-paragraph'.
bug archived.
Request was from
Debbugs Internal Request <help-debbugs <at> gnu.org>
to
internal_control <at> debbugs.gnu.org
.
(Mon, 18 Jan 2021 12:24:07 GMT)
Full text and
rfc822 format available.
This bug report was last modified 4 years and 191 days ago.
Previous Next
GNU bug tracking system
Copyright (C) 1999 Darren O. Benham,
1997,2003 nCipher Corporation Ltd,
1994-97 Ian Jackson.