Dov Feldstern wrote:

Attached find a patch for this bug. OK?

Twice almost the same code sequence. Any chance of factoring this out?

I know... But if you'll take a look at the two functions (paintText and cursorX), the loop at the heart of them is very similar, and a lot of the same things are happening in both functions, except they're written in different forms. But it is actually very very similar. I think that to correctly factor this out would mean rewriting the loop for both these functions, which is not something for now...

I've been thinking about this some more, and I think I have a direction
for solving this:

During painting, we should cache the cursorX positions. Then we won't
have to repeat the same code again inside cursorX, that will solve the
repeated code issue. It will also provide some speedup to the cursorX
function, which currently goes through all of the characters on the line
in order to calculate the position, on every single cursor blink!

This would require some minor changes to the painting code --- for
example, the painting code may not currently calculate X positions for
every character, because we try to paint whole words at a time. But this
should be easy to solve. And it would still be less expensive, because
the painting code is called less frequently than the cursorX code; and
anyhow, I'm pretty sure that every time painting occurs (at least in the
cursor's line), cursorX will be called anyhow.

We would also have to decide where the correct place for this cache is
(TextMetrics?); should caching occur for the entire paragraph (or even
document), or just for the line which the cursor is in?

But basically, I think this would solve the repeated code, as well as
provide an efficiency boost.

Comments are welcome!
Dov

Reply via email to