Andre Poenitz wrote:
On Fri, Jun 29, 2007 at 11:17:51AM +0300, Dov Feldstern wrote:
Right now it's being called on every cursor blink, I think (I put in a debug printout, and it prints on every blink); and what it's doing every time is to loop over all the characters from the beginning of the line until the current position, and sum up the widths, in order to get to the current X position. Same thing when you move one position to the right or to the left --- the entire summing start from the beginning of the line. But this calculation was already done when we painted the screen, so there's no need to do it again.

This may not be very costly relative to the painting, but it's certainly much more wasteful than it needs to be.

And the proposed solution is to have a cache for each position in the
document? You lost me...

Andre'


Well, at least for every position in the current line, yes, I propose to cache the cursor X positions; perhaps even for the entire paragraph. The entire document? --- probably it doesn't make sense, but I wouldn't dismiss the idea without thinking about it a bit: caching the positions for the entire document would at the most make the size of the document in memory 1.5 times what it is now (because we'd only need a short for every position which now has a 32-bit character); and what people have been complaining about is runtime, not memory consumption. Of course, the actual caching would only happen when we paint, so whatever's not painted won't be updated; but that's fine, because the cursor isn't going anywhere that's not painted, anyhow. So at any given point in time only a small portion of the cache is actually valid, but it's exactly those portions which we need at that time.

But again, the entire document may be overkill. The entire paragraph, or at the very least the current line --- I like my idea ;) .

Dov

Reply via email to