From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Lars Magne Ingebrigtsen Newsgroups: gmane.emacs.bugs Subject: bug#13949: 24.4.1; `fill-paragraph' should not always put the buffer as modified Date: Mon, 28 Mar 2016 13:27:49 +0200 Message-ID: References: <56F12360.5030301@ro.ru> <83y49a4hga.fsf@gnu.org> <56F1837D.4060300@ro.ru> <83io0e4b5r.fsf@gnu.org> <56F19203.5040501@ro.ru> <87a8lkd2bc.fsf@wanadoo.es> <83lh54ynol.fsf@gnu.org> <83a8ljzz3h.fsf@gnu.org> <8360w7zyh3.fsf@gnu.org> NNTP-Posting-Host: plane.gmane.org Mime-Version: 1.0 Content-Type: text/plain X-Trace: ger.gmane.org 1459164504 2746 80.91.229.3 (28 Mar 2016 11:28:24 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Mon, 28 Mar 2016 11:28:24 +0000 (UTC) To: 13949@debbugs.gnu.org Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Mon Mar 28 13:28:12 2016 Return-path: Envelope-to: geb-bug-gnu-emacs@m.gmane.org Original-Received: from lists.gnu.org ([208.118.235.17]) by plane.gmane.org with esmtp (Exim 4.69) (envelope-from ) id 1akVL9-0003IC-T6 for geb-bug-gnu-emacs@m.gmane.org; Mon, 28 Mar 2016 13:28:12 +0200 Original-Received: from localhost ([::1]:40283 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1akVL8-0001bj-JJ for geb-bug-gnu-emacs@m.gmane.org; Mon, 28 Mar 2016 07:28:10 -0400 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:54995) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1akVL3-0001b3-QK for bug-gnu-emacs@gnu.org; Mon, 28 Mar 2016 07:28:07 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1akVL0-0004tZ-JY for bug-gnu-emacs@gnu.org; Mon, 28 Mar 2016 07:28:05 -0400 Original-Received: from debbugs.gnu.org ([208.118.235.43]:43718) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1akVL0-0004tV-GR for bug-gnu-emacs@gnu.org; Mon, 28 Mar 2016 07:28:02 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1akVL0-0000sj-Cf for bug-gnu-emacs@gnu.org; Mon, 28 Mar 2016 07:28:02 -0400 X-Loop: help-debbugs@gnu.org Resent-From: Lars Magne Ingebrigtsen Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Mon, 28 Mar 2016 11:28:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 13949 X-GNU-PR-Package: emacs X-GNU-PR-Keywords: Original-Received: via spool by 13949-submit@debbugs.gnu.org id=B13949.14591644753376 (code B ref 13949); Mon, 28 Mar 2016 11:28:02 +0000 Original-Received: (at 13949) by debbugs.gnu.org; 28 Mar 2016 11:27:55 +0000 Original-Received: from localhost ([127.0.0.1]:40845 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1akVKs-0000sO-Oz for submit@debbugs.gnu.org; Mon, 28 Mar 2016 07:27:54 -0400 Original-Received: from hermes.netfonds.no ([80.91.224.195]:44999) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1akVKr-0000sG-KS for 13949@debbugs.gnu.org; Mon, 28 Mar 2016 07:27:54 -0400 Original-Received: from cm-84.215.1.64.getinternet.no ([84.215.1.64] helo=stories) by hermes.netfonds.no with esmtpsa (TLS1.2:DHE_RSA_AES_128_CBC_SHA1:128) (Exim 4.84_2) (envelope-from ) id 1akVKo-0000jF-A7 for 13949@debbugs.gnu.org; Mon, 28 Mar 2016 13:27:52 +0200 Face: iVBORw0KGgoAAAANSUhEUgAAADAAAAAwBAMAAAClLOS0AAAAFVBMVEXx0LE2ISr968Lfu578 3rj317WXdGdrrzSBAAACXUlEQVQ4jV3UzZKjIBAAYBJjzul1i3OqJZ51SDy7DOyZysicg9bw/o+w 3RAzU0tVSsNHN/+KYKlclTGIqHYy3fA887vgentQ9KoJQI7Gmg0Mcj02qI4g04K5iJmFM7UNXkYp 0xfucUtlrEXsCERKaUUz0f8Cqs2g7gSJWt/3W6p2z6kQx5SkuU/BGQJKpHDBvgBIPDjvSwSl7Nvf mmAg2BvvBfeByih8HyQNRhHAFScxcYTiiAHgxCAjPIwSuXMkOAMA9XEeJAANy9dbH+0TdpDhtVa2 K6A+6SnNN7j4hA96rvvXWtkjPKGjFl/WvCDS4jFgFxOs4b5BiLCOBAo7SFG7+QWfMnGEMgSpd5xL 8NYGLzTD5dDSTtX2CTOB1wOBEx1IbpqB6kPwVYF3GtQGbmYQEU7KCZrHiZreuXNHfQSXgXKOUfpr hhDsFnG14e6PoG88XlEHLt7TzJs53KcK1lv4ARWtajM7M4nY1BnCnOEIzdAc3H4Sxw1KxA4eab05 82cVzc0ftlSeQTa92P+FURYQW8QaG52WkTbqJg7fqQbQkVZy0QVMSVV7H6GHdR1/dTIxWFNS0TSk lmv/sXR0eBksQ10LQQC69kv7E4IQR0gM7qEIdAHhawZNe1rpFTPMDLWniB1oPSTdJ74Ij2ouEQxS 63GdXYa+shm4DA1BM1cJuxR7UcDTb1y1fqODIAmkuH1D0gR81LGNTT5Sz1QjA81B4jk+8nku9VWO wIo+GJjE9T+gT4Ki+97zYK17Ag/qLd85vPQcEJ5dZCgRFz60jqHXVaTRjkuJUI4PVP0PlNneFLie r24AAAAASUVORK5CYII= Mail-Copies-To: never In-Reply-To: (Lars Magne Ingebrigtsen's message of "Mon, 28 Mar 2016 12:39:54 +0200") User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/25.1.50 (gnu/linux) X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 208.118.235.43 X-BeenThere: bug-gnu-emacs@gnu.org List-Id: "Bug reports for GNU Emacs, the Swiss army knife of text editors" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Original-Sender: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Xref: news.gmane.org gmane.emacs.bugs:115632 Archived-At: I've now made a simple buffer hashing function (that does not take text properties into account) to see how slow this would be. The following form (with-temp-buffer (dotimes (i 10000) (insert (make-string 100 ?k) "\n")) (benchmark-run 1000 (buffer-hash))) takes 2.7 seconds (that's 1000 1MB buffers), and unsurprisingly (with-temp-buffer (dotimes (i 10000000) (insert (make-string 100 ?k) "\n")) (benchmark-run 1 (progn (message "%s" (buffer-size) (buffer-hash))))) (which is 1 1GB buffer) takes the same amount of time. :-) (This is on a 2.7GHz i5 from like five years ago.) So on big buffers this isn't really something you'd want to run a lot, but it's workable (especially since in the `M-q' case you'd only run it if the buffer isn't already modified). So... diff --git a/src/fns.c b/src/fns.c index 0e3fc27..d027058 100644 --- a/src/fns.c +++ b/src/fns.c @@ -4737,6 +4737,22 @@ It should be the case that if (eq (funcall HASH x1) (funcall HASH x2)) #include "sha256.h" #include "sha512.h" +static Lisp_Object +make_digest_string (Lisp_Object digest, int digest_size) +{ + unsigned char *p = SDATA (digest); + int i; + + for (i = digest_size - 1; i >= 0; i--) + { + static char const hexdigit[16] = "0123456789abcdef"; + int p_i = p[i]; + p[2 * i] = hexdigit[p_i >> 4]; + p[2 * i + 1] = hexdigit[p_i & 0xf]; + } + return digest; +} + /* ALGORITHM is a symbol: md5, sha1, sha224 and so on. */ static Lisp_Object @@ -4936,17 +4952,7 @@ It should be the case that if (eq (funcall HASH x1) (funcall HASH x2)) SSDATA (digest)); if (NILP (binary)) - { - unsigned char *p = SDATA (digest); - for (i = digest_size - 1; i >= 0; i--) - { - static char const hexdigit[16] = "0123456789abcdef"; - int p_i = p[i]; - p[2 * i] = hexdigit[p_i >> 4]; - p[2 * i + 1] = hexdigit[p_i & 0xf]; - } - return digest; - } + return make_digest_string (digest, digest_size); else return make_unibyte_string (SSDATA (digest), digest_size); } @@ -4997,6 +5003,44 @@ It should be the case that if (eq (funcall HASH x1) (funcall HASH x2)) { return secure_hash (algorithm, object, start, end, Qnil, Qnil, binary); } + +DEFUN ("buffer-hash", Fbuffer_hash, Sbuffer_hash, 0, 1, 0, + doc: /* Return a hash of the contents of BUFFER-OR-NAME. +If nil, use the current buffer." */ ) + (Lisp_Object buffer_or_name) +{ + Lisp_Object buffer; + struct buffer *b; + struct sha1_ctx ctx; + Lisp_Object digest = make_uninit_string (SHA1_DIGEST_SIZE * 2); + + if (NILP (buffer_or_name)) + buffer = Fcurrent_buffer (); + else + buffer = Fget_buffer (buffer_or_name); + if (NILP (buffer)) + nsberror (buffer_or_name); + + b = XBUFFER (buffer); + sha1_init_ctx (&ctx); + + /* Process the first part of the buffer. */ + sha1_process_bytes (BUF_BEG_ADDR (b), + BUF_GPT_BYTE (b) - BUF_BEG_BYTE (b), + &ctx); + + /* If the gap is before the end of the buffer, process the last half + of the buffer. */ + if (BUF_GPT_BYTE (b) < BUF_Z_BYTE (b)) + sha1_process_bytes (BUF_GAP_END_ADDR (b), + BUF_Z_BYTE (b) - (BUF_GPT_BYTE (b) + BUF_GAP_SIZE (b)), + &ctx); + + sha1_finish_ctx (&ctx, SSDATA (digest)); + return make_digest_string (digest, SHA1_DIGEST_SIZE); +} + + void syms_of_fns (void) @@ -5156,6 +5200,7 @@ It should be the case that if (eq (funcall HASH x1) (funcall HASH x2)) defsubr (&Sbase64_decode_string); defsubr (&Smd5); defsubr (&Ssecure_hash); + defsubr (&Sbuffer_hash); defsubr (&Slocale_info); hashtest_eq.name = Qeq; -- (domestic pets only, the antidote for overdose, milk.) bloggy blog: http://lars.ingebrigtsen.no