From: Alan Mackenzie <acm@muc.de>
To: Eli Zaretskii <eliz@gnu.org>
Cc: Stefan Monnier <monnier@iro.umontreal.ca>,
yu jie <yujie052@gmail.com>,
emacs-devel@gnu.org
Subject: Re: ntemacs hangs when openning the attached file
Date: Fri, 23 May 2008 21:01:23 +0000 [thread overview]
Message-ID: <20080523210123.GB4046@muc.de> (raw)
In-Reply-To: <uy76mebyo.fsf@gnu.org>
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" <yujie052@gmail.com>
> >
> > 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).
next prev parent reply other threads:[~2008-05-23 21:01 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
[not found] <42b562540805062101s3e79eecel5ddc5b19821deda2@mail.gmail.com>
2008-05-07 8:48 ` ntemacs hangs when openning the attached file Eli Zaretskii
2008-05-20 16:13 ` Alan Mackenzie
2008-05-22 4:42 ` Stefan Monnier
2008-05-23 21:01 ` Alan Mackenzie [this message]
2008-05-23 21:36 ` Stefan Monnier
2008-05-24 13:16 ` Alan Mackenzie
2008-05-24 8:18 ` Eli Zaretskii
2008-05-24 13:17 ` Alan Mackenzie
2008-05-07 17:34 ` Richard M Stallman
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20080523210123.GB4046@muc.de \
--to=acm@muc.de \
--cc=eliz@gnu.org \
--cc=emacs-devel@gnu.org \
--cc=monnier@iro.umontreal.ca \
--cc=yujie052@gmail.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this external index
https://git.savannah.gnu.org/cgit/emacs.git
https://git.savannah.gnu.org/cgit/emacs/org-mode.git
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.