]> git.eshelyaron.com Git - emacs.git/commitdiff
Use `line-number-at-pos' in `count-lines'
authorLars Ingebrigtsen <larsi@gnus.org>
Sun, 7 Feb 2021 16:29:57 +0000 (17:29 +0100)
committerLars Ingebrigtsen <larsi@gnus.org>
Sun, 7 Feb 2021 16:30:02 +0000 (17:30 +0100)
* lisp/simple.el (count-lines): Use `line-number-at-pos', which
should be faster.

lisp/simple.el

index 60c13166e70bb1dc0a4dad4d9d57e1357b281398..568debaa6129eaecc72e36579521d63bb5f2abb2 100644 (file)
@@ -1453,9 +1453,9 @@ included in the count."
   (save-excursion
     (save-restriction
       (narrow-to-region start end)
-      (goto-char (point-min))
       (cond ((and (not ignore-invisible-lines)
                   (eq selective-display t))
+             (goto-char (point-min))
             (save-match-data
               (let ((done 0))
                 (while (re-search-forward "\n\\|\r[^\n]" nil t 40)
@@ -1468,6 +1468,7 @@ included in the count."
                     (1+ done)
                   done))))
            (ignore-invisible-lines
+             (goto-char (point-min))
             (save-match-data
               (- (buffer-size)
                   (forward-line (buffer-size))
@@ -1482,7 +1483,11 @@ included in the count."
                                (assq prop buffer-invisibility-spec)))
                          (setq invisible-count (1+ invisible-count))))
                    invisible-count))))
-           (t (- (buffer-size) (forward-line (buffer-size))))))))
+           (t
+             (goto-char (point-max))
+             (if (bolp)
+                 (1- (line-number-at-pos))
+               (line-number-at-pos)))))))
 
 (defcustom what-cursor-show-names nil
   "Whether to show character names in `what-cursor-position'."