line-number-at-pos
当点接近缓冲区的末端时,该函数(当重复约50次时)会导致半大缓冲区(例如50,000条线)明显减速。减速是指总计约1.35秒。
与其使用100%的elisp
函数对行进行计数并转到缓冲区的顶部,我对一种混合方法感兴趣,该方法利用了负责出现在模式行上的行号的内置C功能。不管缓冲区的大小如何,出现在模式行上的行号都会以光速出现。
这是一个测试功能:
(defmacro measure-time (&rest body)
"Measure the time it takes to evaluate BODY.
http://lists.gnu.org/archive/html/help-gnu-emacs/2008-06/msg00087.html"
`(let ((time (current-time)))
,@body
(message "%.06f" (float-time (time-since time)))))
(measure-time
(let* (
line-numbers
(window-start (window-start))
(window-end (window-end)))
(save-excursion
(goto-char window-end)
(while
(re-search-backward "\n" window-start t)
(push (line-number-at-pos) line-numbers)))
line-numbers))