From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Alan Mackenzie Newsgroups: gmane.emacs.devel Subject: Re: ntemacs hangs when openning the attached file Date: Fri, 23 May 2008 21:01:23 +0000 Message-ID: <20080523210123.GB4046@muc.de> References: <42b562540805062101s3e79eecel5ddc5b19821deda2@mail.gmail.com> NNTP-Posting-Host: lo.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Trace: ger.gmane.org 1211575370 18958 80.91.229.12 (23 May 2008 20:42:50 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Fri, 23 May 2008 20:42:50 +0000 (UTC) Cc: Stefan Monnier , yu jie , emacs-devel@gnu.org To: Eli Zaretskii Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Fri May 23 22:43:27 2008 Return-path: Envelope-to: ged-emacs-devel@m.gmane.org Original-Received: from lists.gnu.org ([199.232.76.165]) by lo.gmane.org with esmtp (Exim 4.50) id 1Jze5N-0008UP-Vp for ged-emacs-devel@m.gmane.org; Fri, 23 May 2008 22:41:58 +0200 Original-Received: from localhost ([127.0.0.1]:56639 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1Jze4d-0003tP-Am for ged-emacs-devel@m.gmane.org; Fri, 23 May 2008 16:41:11 -0400 Original-Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1Jze4Y-0003tK-Hj for emacs-devel@gnu.org; Fri, 23 May 2008 16:41:06 -0400 Original-Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1Jze4W-0003t8-Ul for emacs-devel@gnu.org; Fri, 23 May 2008 16:41:05 -0400 Original-Received: from [199.232.76.173] (port=41348 helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1Jze4W-0003t5-QD for emacs-devel@gnu.org; Fri, 23 May 2008 16:41:04 -0400 Original-Received: from colin.muc.de ([193.149.48.1]:4102 helo=mail.muc.de) by monty-python.gnu.org with esmtps (TLS-1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.60) (envelope-from ) id 1Jze4W-0005Px-E6 for emacs-devel@gnu.org; Fri, 23 May 2008 16:41:04 -0400 Original-Received: (qmail 22943 invoked by uid 3782); 23 May 2008 20:41:00 -0000 Original-Received: from acm.muc.de (pD9E5049D.dip.t-dialin.net [217.229.4.157]) by colin2.muc.de (tmda-ofmipd) with ESMTP; Fri, 23 May 2008 22:40:57 +0200 Original-Received: (qmail 8015 invoked by uid 1000); 23 May 2008 21:01:23 -0000 Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.5.9i X-Delivery-Agent: TMDA/1.1.5 (Fettercairn) X-Primary-Address: acm@muc.de X-detected-kernel: by monty-python.gnu.org: FreeBSD 4.6-4.9 X-BeenThere: emacs-devel@gnu.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: "Emacs development discussions." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Original-Sender: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Errors-To: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Xref: news.gmane.org gmane.emacs.devel:97615 Archived-At: Hi, Eli and yu! On Wed, May 07, 2008 at 11:48:47AM +0300, Eli Zaretskii wrote: > > Date: Wed, 7 May 2008 12:01:38 +0800 > > From: "yu jie" > > > > The current CVS header version hangs when openning the attached file. > No, it doesn't hang, it just takes a lot of time to visit this file. > I measured 61 seconds on a 3GHz machine. This file has 86406 lines, > and uses some pretty non-standard formatting, such as this one: The problem was that c-neutralize-syntax-in-CPP was inefficiently coded. I've optimised it using essentially only Emacs primitives in the defun's main loop. It now runs almost 2 orders of magnitude faster. Eli, I'd appreciate it very much indeed if you could review this new code, please - earlier versions of it were peculiarly troublesome. Thanks! Here's the patch: *** cc-mode.el~ 2008-05-23 20:42:45.653994480 +0000 --- cc-mode.el 2008-05-23 20:50:43.941283760 +0000 *************** *** 837,863 **** ;; ;; This function is the C/C++/ObjC value of `c-before-font-lock-function'. ;; ;; This function might do invisible changes. ! (c-save-buffer-state (limits mbeg+1 beg end) ! ;; First calculate the region, possibly to be extended. ! (setq beg (min begg c-old-BOM)) (goto-char endd) ! (when (c-beginning-of-macro) ! (c-end-of-macro)) (setq end (max (+ (- c-old-EOM old-len) (- endd begg)) (point))) ;; Clear all old punctuation properties (c-clear-char-property-with-value beg end 'syntax-table '(1)) (goto-char beg) (while (and (< (point) end) (search-forward-regexp c-anchored-cpp-prefix end t)) ;; If we've found a "#" inside a string/comment, ignore it. ! (if (setq limits (c-literal-limits)) ! (goto-char (cdr limits)) (setq mbeg+1 (point)) (c-end-of-macro) ; Do we need to go forward 1 char here? No! ! (c-neutralize-CPP-line mbeg+1 (point)))))) (defun c-before-change (beg end) ;; Function to be put on `before-change-function'. Primarily, this calls --- 837,881 ---- ;; ;; This function is the C/C++/ObjC value of `c-before-font-lock-function'. ;; + ;; Note: SPEED _MATTERS_ IN THIS FUNCTION!!! + ;; ;; This function might do invisible changes. ! (c-save-buffer-state (limits mbeg+1 beg end pps-position pps-state) ! ;; First determine the region, (beg end), which may need "neutralizing". ! ;; This may not start inside a string or comment, or a macro. ! (goto-char begg) ! (if (setq limits (c-literal-limits)) ! (goto-char (cdr limits))) ; go forward out of any string or comment. ! (c-beginning-of-macro) ! (setq beg (min (point) c-old-BOM)) ! (goto-char endd) ! (if (setq limits (c-literal-limits)) ! (goto-char (car limits))) ; go backward out of any string or comment. ! (if (c-beginning-of-macro) ! (c-end-of-macro)) (setq end (max (+ (- c-old-EOM old-len) (- endd begg)) (point))) + ;; Clear all old punctuation properties (c-clear-char-property-with-value beg end 'syntax-table '(1)) (goto-char beg) + (setq pps-position beg pps-state nil) (while (and (< (point) end) (search-forward-regexp c-anchored-cpp-prefix end t)) ;; If we've found a "#" inside a string/comment, ignore it. ! (setq pps-state ! (parse-partial-sexp pps-position (point) nil nil pps-state) ! pps-position (point)) ! (unless (or (nth 3 pps-state) ; in a string? ! (nth 4 pps-state)) ; in a comment? (setq mbeg+1 (point)) (c-end-of-macro) ; Do we need to go forward 1 char here? No! ! (c-neutralize-CPP-line mbeg+1 (point)) ! (setq pps-state ! (parse-partial-sexp pps-position (point) nil nil pps-state) ! pps-position (point)))))) (defun c-before-change (beg end) ;; Function to be put on `before-change-function'. Primarily, this calls -- Alan Mackenzie (Nuremberg, Germany).