This must be because getbufline() always returns a list of strings.
Creating the list, adding a list item and then making a copy of the text
takes longer. Using getline() (just to try it out, wouldn't work in
your actual code) brings the difference down to less than two times.
Not storing the result of getbufline() in a variable, but passing it to
byteidx() with "->" also helps make it faster.
The range should be bigger, I used 10x to get more stable results. As a
rule of thumb: the profiling time should be at least 100 msec to avoid
too much fluctuation.
After making some adjustments it is now only about 16% slower.
I'll make a patch to get getbufoneline(), since just getting the string
for one line would be very common and it is about twice as fast.
The name getbufoneline() isn't nice, couldn't come up with something
better. Should have called the existing function getbuflines() instead
of getbufline(), but we can't change that now.
The resulting essential line in ProfByteIdxFunction():
idx = getbufoneline('', 5344)->byteidx(77)
Should really update the help to avoid the term "column number", it is
confusing. The remark "Most useful when the column is "$"" is a hint
that is easily missed.
OK, I finally see your point, sorry it took so long.
Unfortunately, adding a third argument that is a flag, indicating whether
the second argument means bytes or characters, conflicts with other
places where the third argument is "coloff". This is used with
virtcol() for example.
You also still have the limitation that col() only works for the current
buffer.
Making matchaddpos() accept a character index instead of a byte index is
going to trigger doing this in many more places. And internally the
conversion will have to be done anyway. Therefore sticking to using a
byte index in most places that deal with text avoids a lot of complexity
in the arguments of the functions.
So let's go back to making the character index to byte index conversion
fast. That is a generic solution and avoids changes all over the place.
Please try out the new getbufoneline() function, as mentioned above.
If the performance is indeed quite bad, adding a function that converts
a text location in a buffer specified by character index to a byte index
could be a solution. Perhaps:
bufcol({buf}, {expr}) {expr} a string like with col()
bufcol({buf}, {lnum}, {expr}) {expr} a string like with col()
bufcol({buf}, {lnum}, {charidx})
--
hundred-and-one symptoms of being an internet addict:
100. The most exciting sporting events you noticed during summer 1996
was Netscape vs. Microsoft.