[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[elpa] externals/phps-mode 282115f 357/405: Using incremental line-numbe
From: |
Stefan Monnier |
Subject: |
[elpa] externals/phps-mode 282115f 357/405: Using incremental line-number calculation as optimization |
Date: |
Sat, 13 Jul 2019 10:00:48 -0400 (EDT) |
branch: externals/phps-mode
commit 282115f6a45b99a5949a2668b7a88a824eae297d
Author: Christian Johansson <address@hidden>
Commit: Christian Johansson <address@hidden>
Using incremental line-number calculation as optimization
---
phps-mode-functions.el | 28 +++++++++++++++++++++++++---
1 file changed, 25 insertions(+), 3 deletions(-)
diff --git a/phps-mode-functions.el b/phps-mode-functions.el
index 9186e9e..c50646e 100644
--- a/phps-mode-functions.el
+++ b/phps-mode-functions.el
@@ -47,6 +47,8 @@
;; NOTE Also format white-space inside the line, i.e. after function
declarations?
+;; TODO Optimize line-number-at-pos
+
(defun phps-mode-functions-get-buffer-changes-start ()
"Get buffer change start."
phps-mode-functions-buffer-changes-start)
@@ -75,6 +77,19 @@
(phps-mode-functions-process-current-buffer)
phps-mode-functions-imenu)
+(defun phps-mode-functions--get-lines-in-buffer (beg end)
+ "Return the number of lines in buffer between BEG and END."
+ (phps-mode-functions--get-lines-in-string (buffer-substring-no-properties
beg end)))
+
+(defun phps-mode-functions--get-lines-in-string (string)
+ "Return the number of lines in STRING."
+ (let ((lines-in-string 0)
+ (start 0))
+ (while (string-match "[\n\C-m]" string start)
+ (setq start (match-end 0))
+ (setq lines-in-string (1+ lines-in-string)))
+ lines-in-string))
+
(defun phps-mode-functions--process-current-buffer ()
"Process current buffer and generation indentation and Imenu in one
iteration. Complexity: O(n)."
(if (boundp 'phps-mode-lexer-tokens)
@@ -144,7 +159,8 @@
(imenu-in-class-name nil)
(imenu-in-function-declaration nil)
(imenu-in-function-name nil)
- (imenu-nesting-level 0))
+ (imenu-nesting-level 0)
+ (incremental-line-number 1))
(push `(END_PARSE ,(point-max) . ,(point-max)) tokens)
@@ -157,13 +173,19 @@
(next-token-start-line-number nil)
(next-token-end-line-number nil))
+ (when token
+ (setq incremental-line-number (+ incremental-line-number
(phps-mode-functions--get-lines-in-buffer token-end next-token-start))))
+
;; Handle the pseudo-token for last-line
(if (equal next-token 'END_PARSE)
(progn
(setq next-token-start-line-number (1+
token-start-line-number))
(setq next-token-end-line-number (1+
token-end-line-number)))
- (setq next-token-start-line-number (line-number-at-pos
next-token-start t))
- (setq next-token-end-line-number (line-number-at-pos
next-token-end t)))
+ (setq next-token-start-line-number incremental-line-number)
+ (setq incremental-line-number (+ incremental-line-number
(phps-mode-functions--get-lines-in-buffer next-token-start next-token-end)))
+ (setq next-token-end-line-number incremental-line-number)
+ (when phps-mode-functions-verbose
+ (message "Token '%s' pos: %s-%s lines: %s-%s" next-token
next-token-start next-token-end next-token-start-line-number
next-token-end-line-number)))
;; Token logic
(when token
- [elpa] externals/phps-mode a8fbe7d 344/405: Improved syntax coloring of =, % and more, (continued)
- [elpa] externals/phps-mode a8fbe7d 344/405: Improved syntax coloring of =, % and more, Stefan Monnier, 2019/07/13
- [elpa] externals/phps-mode 64e1789 356/405: Fixed indentation were assignments end at next line, Stefan Monnier, 2019/07/13
- [elpa] externals/phps-mode 83d5de8 355/405: Removed uneccesary debug output in unit test, Stefan Monnier, 2019/07/13
- [elpa] externals/phps-mode abd78a0 359/405: Work on incremental newline logic, Stefan Monnier, 2019/07/13
- [elpa] externals/phps-mode d8ad25b 341/405: Passes new test indentation of multi-line double-arrow inside assignment, Stefan Monnier, 2019/07/13
- [elpa] externals/phps-mode e7cb803 346/405: Added another indentation test, Stefan Monnier, 2019/07/13
- [elpa] externals/phps-mode dabe0ea 345/405: Added failing indentation test for multi-dimension array in assignment with double arrows, Stefan Monnier, 2019/07/13
- [elpa] externals/phps-mode d6e6cbc 358/405: Another optimization of line-number-at-pos inside loop, Stefan Monnier, 2019/07/13
- [elpa] externals/phps-mode e681c9c 347/405: Updated color syntax for T_STRING tokens, Stefan Monnier, 2019/07/13
- [elpa] externals/phps-mode c11bcc5 360/405: More work on newline advice, Stefan Monnier, 2019/07/13
- [elpa] externals/phps-mode 282115f 357/405: Using incremental line-number calculation as optimization,
Stefan Monnier <=
- [elpa] externals/phps-mode c118f58 342/405: Added TODO items, Stefan Monnier, 2019/07/13
- [elpa] externals/phps-mode 812dc49 353/405: Removed TODO item, Stefan Monnier, 2019/07/13
- [elpa] externals/phps-mode 834275b 354/405: Fixed indentation calculation of nested alternative control structures, Stefan Monnier, 2019/07/13
- [elpa] externals/phps-mode 62f1fc5 348/405: Added another failing indentation test for return expressions, Stefan Monnier, 2019/07/13
- [elpa] externals/phps-mode 071acc0 349/405: Added support for multi-line return indentation, Stefan Monnier, 2019/07/13
- [elpa] externals/phps-mode 46d0575 373/405: Passes all tests for adding newline and indenting without affect lexer, Stefan Monnier, 2019/07/13
- [elpa] externals/phps-mode 71858d1 374/405: Removed side-effect of END_PARSE token being added to tokens after processing buffer, Stefan Monnier, 2019/07/13
- [elpa] externals/phps-mode 228b657 380/405: Updated README with license logo and Travis CI build status, Stefan Monnier, 2019/07/13
- [elpa] externals/phps-mode 6308e3e 366/405: Removed debug notice, Stefan Monnier, 2019/07/13
- [elpa] externals/phps-mode bd90dc9 370/405: Removed debug output, Stefan Monnier, 2019/07/13