From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Kenichi Handa Newsgroups: gmane.emacs.bugs Subject: bug#12296: 24.1.50; Slow decoding in Rmail Date: Wed, 29 Aug 2012 13:35:17 +0900 Message-ID: <87k3wiuxh6.fsf@gnu.org> References: NNTP-Posting-Host: plane.gmane.org Mime-Version: 1.0 Content-Type: text/plain X-Trace: ger.gmane.org 1346214966 6706 80.91.229.3 (29 Aug 2012 04:36:06 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Wed, 29 Aug 2012 04:36:06 +0000 (UTC) Cc: 12296@debbugs.gnu.org To: rms@gnu.org Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Wed Aug 29 06:36:07 2012 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 1T6a0d-0000UA-9x for geb-bug-gnu-emacs@m.gmane.org; Wed, 29 Aug 2012 06:36:07 +0200 Original-Received: from localhost ([::1]:52224 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1T6a0b-0000X2-4h for geb-bug-gnu-emacs@m.gmane.org; Wed, 29 Aug 2012 00:36:05 -0400 Original-Received: from eggs.gnu.org ([208.118.235.92]:56021) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1T6a0X-0000Wq-Sp for bug-gnu-emacs@gnu.org; Wed, 29 Aug 2012 00:36:03 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1T6a0W-0007EA-I0 for bug-gnu-emacs@gnu.org; Wed, 29 Aug 2012 00:36:01 -0400 Original-Received: from debbugs.gnu.org ([140.186.70.43]:45652) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1T6a0W-0007E4-EQ for bug-gnu-emacs@gnu.org; Wed, 29 Aug 2012 00:36:00 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.72) (envelope-from ) id 1T6a1W-0004UG-AG for bug-gnu-emacs@gnu.org; Wed, 29 Aug 2012 00:37:02 -0400 X-Loop: help-debbugs@gnu.org Resent-From: Kenichi Handa Original-Sender: debbugs-submit-bounces@debbugs.gnu.org Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Wed, 29 Aug 2012 04:37:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 12296 X-GNU-PR-Package: emacs X-GNU-PR-Keywords: Original-Received: via spool by 12296-submit@debbugs.gnu.org id=B12296.134621501417234 (code B ref 12296); Wed, 29 Aug 2012 04:37:02 +0000 Original-Received: (at 12296) by debbugs.gnu.org; 29 Aug 2012 04:36:54 +0000 Original-Received: from localhost ([127.0.0.1]:55198 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.72) (envelope-from ) id 1T6a1O-0004Tv-6G for submit@debbugs.gnu.org; Wed, 29 Aug 2012 00:36:54 -0400 Original-Received: from fencepost.gnu.org ([208.118.235.10]:43860) by debbugs.gnu.org with esmtp (Exim 4.72) (envelope-from ) id 1T6a1K-0004Tn-VE for 12296@debbugs.gnu.org; Wed, 29 Aug 2012 00:36:52 -0400 Original-Received: from [150.29.149.7] (port=55944 helo=ubuntu) by fencepost.gnu.org with esmtpsa (TLS1.0:DHE_RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1T6a0A-0002Ty-VP; Wed, 29 Aug 2012 00:35:39 -0400 In-Reply-To: (message from Richard Stallman on Tue, 28 Aug 2012 16:26:30 -0400) X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.13 Precedence: list X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.6 (newer, 2) X-Received-From: 140.186.70.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:63571 Archived-At: In article , Richard Stallman writes: > Mime-decoding in Rmail the message included below > takes 10 seconds on my machine (which is rather slow). > I am pretty sure it is due to the character code, > because in general messages in Russian are slow > and others are not. I include this so you get an example. I think the slowness is because of quoted-printable-decode-region (in lisp/gnus/qp.el). It is not well tuned for speed, but I think that's because the quoted-printable encoding is not intended to be used for such a mostly non-ASCII text. RFC2045 says: ------------------------------------------------------------ 6.7. Quoted-Printable Content-Transfer-Encoding The Quoted-Printable encoding is intended to represent data that largely consists of octets that correspond to printable characters in the US-ASCII character set. ------------------------------------------------------------ Anyway, here's a little bit tuned version. Could you please try it. ------------------------------------------------------------ (defun qp-decode-hex (n1 n2) (+ (* (if (<= n1 ?9) (- n1 ?0) (+ (- n1 ?A) 10)) 16) (if (<= n2 ?9) (- n2 ?0) (+ (- n2 ?A) 10)))) (defun quoted-printable-decode-region (from to &optional coding-system) "Decode quoted-printable in the region between FROM and TO, per RFC 2045. If CODING-SYSTEM is non-nil, decode bytes into characters with that coding-system. Interactively, you can supply the CODING-SYSTEM argument with \\[universal-coding-system-argument]. The CODING-SYSTEM argument is a historical hangover and is deprecated. QP encodes raw bytes and should be decoded into raw bytes. Decoding them into characters should be done separately." (interactive ;; Let the user determine the coding system with "C-x RET c". (list (region-beginning) (region-end) coding-system-for-read)) (unless (mm-coding-system-p coding-system) ; e.g. `ascii' from Gnus (setq coding-system nil)) (save-excursion (save-restriction ;; RFC 2045: ``An "=" followed by two hexadecimal digits, one ;; or both of which are lowercase letters in "abcdef", is ;; formally illegal. A robust implementation might choose to ;; recognize them as the corresponding uppercase letters.'' (let ((case-fold-search t)) (narrow-to-region from to) ;; Do this in case we're called from Gnus, say, in a buffer ;; which already contains non-ASCII characters which would ;; then get doubly-decoded below. (if coding-system (mm-encode-coding-region (point-min) (point-max) coding-system)) (goto-char (point-min)) (while (and (skip-chars-forward "^=") (not (eobp))) (cond ((eq (char-after (1+ (point))) ?\n) (delete-char 2)) ((looking-at "\\(=[0-9A-F][0-9A-F]\\)+") (let* ((n (/ (- (match-end 0) (point)) 3)) (str (make-string n 0)) (i 0)) (while (< i n) (aset str i (qp-decode-hex (char-after (1+ (point))) (char-after (+ 2 (point))))) (setq i (1+ i)) (forward-char 3)) (delete-region (match-beginning 0) (match-end 0)) (insert str))) (t (message "Malformed quoted-printable text") (forward-char))))) (if coding-system (mm-decode-coding-region (point-min) (point-max) coding-system))))) ------------------------------------------------------------ --- Kenichi Handa handa@gnu.org