all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
* Optimizations for flymake
@ 2004-11-01 22:37 Kim F. Storm
  2004-11-02  0:17 ` Stefan
  0 siblings, 1 reply; 9+ messages in thread
From: Kim F. Storm @ 2004-11-01 22:37 UTC (permalink / raw)
  Cc: emacs-devel


Hi Pavel,

The byte-compiler explicitly knows how to handle (i.e. eliminate)
code conditioned by (if (featurep 'xemacs) ...) and it is also
faster to use defsubst for trivial functions.

Here is a patch to flymake.el which uses these optimizations, and also
passes the byte-compiler without warnings (except for makehash which is
obsolete in 21.4):


*** flymake.el	01 Nov 2004 23:10:05 +0100	1.4
--- flymake.el	01 Nov 2004 23:32:52 +0100	
***************
*** 36,83 ****
  (provide 'flymake)
  
  ;;;; [[ Overlay compatibility
  (autoload 'make-overlay            "overlay" "Overlay compatibility kit." t)
  (autoload 'overlayp                "overlay" "Overlay compatibility kit." t)
  (autoload 'overlays-in             "overlay" "Overlay compatibility kit." t)
  (autoload 'delete-overlay          "overlay" "Overlay compatibility kit." t)
  (autoload 'overlay-put             "overlay" "Overlay compatibility kit." t)
  (autoload 'overlay-get             "overlay" "Overlay compatibility kit." t)
  ;;;; ]]
  
  ;;;; [[ cross-emacs compatibility routines
! (defvar flymake-emacs
!     (cond
! 	((string-match "XEmacs" emacs-version)  'xemacs)
! 	(t                                      'emacs)
! 	)
!     "Currently used emacs flavor"
! )
! 
! (defun flymake-makehash(&optional test)
!     (cond
! 	((equal flymake-emacs 'xemacs)  (if test (make-hash-table :test test) (make-hash-table)))
! 	(t                              (makehash test))	
!     )
! )
  
- (defun flymake-time-to-float(&optional tm)
- 	"Convert `current-time` to a float number of seconds."
- 	(multiple-value-bind (s0 s1 s2) (or tm (current-time))
- 	  (+ (* (float (ash 1 16)) s0) (float s1) (* 0.0000001 s2)))
- )
  (defun flymake-float-time()
!     (cond
! 	((equal flymake-emacs 'xemacs)  (flymake-time-to-float (current-time)))
! 	(t                              (float-time))
!     )
! )
! 
! (defun flymake-replace-regexp-in-string(regexp rep str)
!     (cond
! 	((equal flymake-emacs 'xemacs)  (replace-in-string str regexp rep))
! 	(t                              (replace-regexp-in-string regexp rep str))
! 	)
! )
  
  (defun flymake-split-string-remove-empty-edges(str pattern)
      "split, then remove first and/or last in case it's empty"
--- 36,68 ----
  (provide 'flymake)
  
  ;;;; [[ Overlay compatibility
+ (if (featurep 'xemacs) (progn
  (autoload 'make-overlay            "overlay" "Overlay compatibility kit." t)
  (autoload 'overlayp                "overlay" "Overlay compatibility kit." t)
  (autoload 'overlays-in             "overlay" "Overlay compatibility kit." t)
  (autoload 'delete-overlay          "overlay" "Overlay compatibility kit." t)
  (autoload 'overlay-put             "overlay" "Overlay compatibility kit." t)
  (autoload 'overlay-get             "overlay" "Overlay compatibility kit." t)
+ )) ;; xemacs
  ;;;; ]]
  
  ;;;; [[ cross-emacs compatibility routines
! (defsubst flymake-makehash(&optional test)
!   (if (featurep 'xemacs)
!       (if test (make-hash-table :test test) (make-hash-table))
!     (makehash test)))
  
  (defun flymake-float-time()
!     (if (featurep 'xemacs)
! 	(let ((tm (current-time)))
! 	  (multiple-value-bind (s0 s1 s2) (current-time)
! 			       (+ (* (float (ash 1 16)) s0) (float s1) (* 0.0000001 s2))))
!       (float-time)))
! 
! (defsubst flymake-replace-regexp-in-string(regexp rep str)
!     (if (featurep 'xemacs)
! 	(replace-in-string str regexp rep)
!       (replace-regexp-in-string regexp rep str)))
  
  (defun flymake-split-string-remove-empty-edges(str pattern)
      "split, then remove first and/or last in case it's empty"
***************
*** 91,109 ****
  		splitted
      )
  )
! (defun flymake-split-string(str pattern)
!     (cond
! 	((equal flymake-emacs 'xemacs)  (flymake-split-string-remove-empty-edges str pattern))
! 	(t                              (flymake-split-string-remove-empty-edges str pattern))
!     )
! )
! 
! (defun flymake-get-temp-dir()
!     (cond
! 	((equal flymake-emacs 'xemacs)  (temp-directory))
! 	(t                              temporary-file-directory)
!     )
! )
  
  (defun flymake-line-beginning-position()
      (save-excursion
--- 76,90 ----
  		splitted
      )
  )
! (defsubst flymake-split-string(str pattern)
!     (if (featurep 'xemacs)
! 	(flymake-split-string-remove-empty-edges str pattern)
!       (flymake-split-string-remove-empty-edges str pattern)))
! 
! (defsubst flymake-get-temp-dir()
!     (if (featurep 'xemacs)
! 	(temp-directory)
!       temporary-file-directory))
  
  (defun flymake-line-beginning-position()
      (save-excursion
***************
*** 120,138 ****
  )
  
  (defun flymake-popup-menu(pos menu-data)
!     (cond
!        ((equal flymake-emacs 'xemacs)
! 	    (let* ((x-pos       (nth 0 (nth 0 pos)))
! 		   (y-pos       (nth 1 (nth 0 pos)))
! 		   (fake-event-props  '(button 1 x 1 y 1)))
! 		(setq fake-event-props (plist-put fake-event-props 'x x-pos))
! 		(setq fake-event-props (plist-put fake-event-props 'y y-pos))
! 		(popup-menu (flymake-make-xemacs-menu menu-data) (make-event 'button-press fake-event-props))
! 	    )
!        )
!        (t                              (x-popup-menu pos (flymake-make-emacs-menu menu-data)))
!     )
! )
  
  (defun flymake-make-emacs-menu(menu-data)
      (let* ((menu-title     (nth 0 menu-data))
--- 101,115 ----
  )
  
  (defun flymake-popup-menu(pos menu-data)
!     (if (featurep 'xemacs)
! 	(let* ((x-pos       (nth 0 (nth 0 pos)))
! 	       (y-pos       (nth 1 (nth 0 pos)))
! 	       (fake-event-props  '(button 1 x 1 y 1)))
! 	  (setq fake-event-props (plist-put fake-event-props 'x x-pos))
! 	  (setq fake-event-props (plist-put fake-event-props 'y y-pos))
! 	  (popup-menu (flymake-make-xemacs-menu menu-data) (make-event 'button-press fake-event-props))
! 	  )
!       (x-popup-menu pos (flymake-make-emacs-menu menu-data))))
  
  (defun flymake-make-emacs-menu(menu-data)
      (let* ((menu-title     (nth 0 menu-data))
***************
*** 149,154 ****
--- 126,133 ----
  (defun flymake-nop()
  )
  
+ (if (featurep 'xemacs) (progn
+ 
  (defun flymake-make-xemacs-menu(menu-data)
      (let* ((menu-title     (nth 0 menu-data))
  	   (menu-items     (nth 1 menu-data))
***************
*** 175,194 ****
      )
  )
  
  (defun flymake-current-row()
      "return current row in current frame"
!     (cond
!        ((equal flymake-emacs 'xemacs)  (count-lines (window-start) (point)))
!        (t                              (+ (car (cdr (window-edges))) (count-lines (window-start) (point))))
!     )
! )
! 
! (defun flymake-selected-frame()
!     (cond
!        ((equal flymake-emacs 'xemacs)  (selected-window))
!        (t                              (selected-frame))
!     )
! )
  
  ;;;; ]]
  
--- 154,172 ----
      )
  )
  
+ )) ;; xemacs
+ 
+ 
  (defun flymake-current-row()
      "return current row in current frame"
!     (if (featurep 'xemacs)
! 	(count-lines (window-start) (point))
!       (+ (car (cdr (window-edges))) (count-lines (window-start) (point)))))
! 
! (defsubst flymake-selected-frame()
!     (if (featurep 'xemacs)
! 	(selected-window)
!       (selected-frame)))
  
  ;;;; ]]
  
***************
*** 547,552 ****
--- 525,534 ----
      :type 'integer
  )
  
+ (defvar flymake-included-file-name nil ; this is used to pass a parameter to a sort predicate below
+     ""
+ )
+ 
  (defun flymake-find-possible-master-files(file-name master-file-dirs masks)
      "find (by name and location) all posible master files, which are .cpp and .c for and .h.
  Files are searched for starting from the .h directory and max max-level parent dirs.
***************
*** 593,602 ****
      )
  )
  
- (defvar flymake-included-file-name nil ; this is used to pass a parameter to a sort predicate below
-     ""
- )
- 
  (defun flymake-master-file-compare(file-one file-two)
      "used in sort to move most possible file names to the beginning of the list (File.h -> File.cpp moved to top"
      (and (equal (file-name-sans-extension flymake-included-file-name)
--- 575,580 ----
***************
*** 1270,1276 ****
  	2 4 nil 5)
        )
  	 ;; compilation-error-regexp-alist)
!      (flymake-reformat-err-line-patterns-from-compile-el compilation-error-regexp-alist-alist)) 
      "patterns for matching error/warning lines, (regexp file-idx line-idx err-text-idx). Use flymake-reformat-err-line-patterns-from-compile-el to add patterns from compile.el"
  )
  ;(defcustom flymake-err-line-patterns
--- 1248,1254 ----
  	2 4 nil 5)
        )
  	 ;; compilation-error-regexp-alist)
!      (flymake-reformat-err-line-patterns-from-compile-el compilation-error-regexp-alist-alist))
      "patterns for matching error/warning lines, (regexp file-idx line-idx err-text-idx). Use flymake-reformat-err-line-patterns-from-compile-el to add patterns from compile.el"
  )
  ;(defcustom flymake-err-line-patterns
***************
*** 1959,1964 ****
--- 1937,1954 ----
      (setq minor-mode-alist (cons '(flymake-mode flymake-mode-line) minor-mode-alist))
  )
  
+ (defcustom flymake-start-syntax-check-on-newline t
+     "start syntax check if newline char was added/removed from the buffer"
+     :group 'flymake
+     :type 'boolean
+ )
+ 
+ (defcustom flymake-start-syntax-check-on-find-file t
+     "statr syntax check on find file"
+     :group 'flymake
+     :type 'boolean
+ )
+ 
  ;;;###autoload
  (defun flymake-mode-on()
      "turn flymake mode on"
***************
*** 2004,2015 ****
      )
  )
  
- (defcustom flymake-start-syntax-check-on-newline t
-     "start syntax check if newline char was added/removed from the buffer"
-     :group 'flymake
-     :type 'boolean
- )
- 
  (defun flymake-after-change-function(start stop len)
      "Start syntax check for current buffer if it isn't already running"
      ;+(flymake-log 0 "setting change time to %s" (flymake-float-time))
--- 1994,1999 ----
***************
*** 2038,2049 ****
      )
  )
  
- (defcustom flymake-start-syntax-check-on-find-file t
-     "statr syntax check on find file"
-     :group 'flymake
-     :type 'boolean
- )
- 
  (defun flymake-find-file-hook()
      ;+(when flymake-start-syntax-check-on-find-file
      ;+    (flymake-log 3 "starting syntax check on file open")
--- 2022,2027 ----



-- 
Kim F. Storm <storm@cua.dk> http://www.cua.dk

^ permalink raw reply	[flat|nested] 9+ messages in thread

end of thread, other threads:[~2004-11-03 12:45 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2004-11-01 22:37 Optimizations for flymake Kim F. Storm
2004-11-02  0:17 ` Stefan
2004-11-02  9:10   ` Kim F. Storm
2004-11-02 10:57     ` David Kastrup
2004-11-02 12:21       ` Pavel Kobiakov
2004-11-02 12:34         ` David Kastrup
2004-11-02 15:48           ` Drew Adams
2004-11-03 12:45         ` Richard Stallman
2004-11-02 12:20     ` Stefan

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.