Subject: Re: bug#22763: 25.1.50; Feature Request -- A faster method to obtain line number at position.

From: Lars Ingebrigtsen <[email-masked]>
Date: Sun, 07 Feb 2021 16:07:21 +0100

Eli Zaretskii <[email-masked]> writes:

> My suggestion is instead to expose display_count_lines to Lisp via a
> simple wrapper (that would need to take care of narrowing and such
> likes, something that your proposed API doesn't do, btw). 

I've now added this to Emacs 28 -- line-number-at-position.  In my
tests, it makes `count-lines' about 2x faster than the previous
implementation.

Now, there's a function called `line-number-at-pos' in simple.el (that
I've amended to use `line-number-at-position', so it's even faster), and
it has almost exactly the signature that the new function has.  But it
has the POS parameter optional, and it has an ABSOLUTE parameter.

I didn't actually discover it before I had finished writing the new
function, so I think I'll just extend the new function to have the same
signature, and then remove the simple.el function.

Unless somebody else has a different opinion in the next ten minutes...

-- 
(domestic pets only, the antidote for overdose, milk.)
   bloggy blog: http://lars.ingebrigtsen.no