-
Notifications
You must be signed in to change notification settings - Fork 70
Description
I was reading the code today and found some potential improvements and a problem in the code.
-
Starting with the problem:
InputArea::heightis never set. It starts its life asNoneand stays that way. That meansInputArea::get_heightalways recomputes the height even if nothing changes inInputArea. -
I think it'd be better to invalidate
InputLine::ws_indices(renamed fromInputLine::line_starts) on update. Currently we don't update it untilcalculate_heightis called, and if I update a line and forget to callcalculate_heightthendrawwill render input area incorrectly. -
We should have a fast path for the common case of inserting at the end.
Currently this causes quadratic behavior on paste, where we turn a long string into a series of key press events (see(this comments was incorrect, see my update in the comments section below) I thinkhandle_input_event), and for every key press we compute the whitespace indices from scratch.InputLine::insertcould be easily updated to handle this and efficiently updatews_indiceswhen inserting at the end.This also means
InputLine::calculate_heightshouldn't generatews_indicesfrom scratch if it's already up-to-date (related to the second point above), otherwise the update ininsertwill never be used. -
Similar to the item above, deleting from the end shouldn't require generating the state from scratch.
cc @trevarj