[perf][LOW] InputField hit-test is O(n^2): re-measures whole prefix per char #56
Labels
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set.
Reference
Catcrafts/Crafter.Graphics#56
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Subsystem: InputField
Location:
implementations/Crafter.Graphics-InputField.cpp:114-137Impact: LOW · Effort: Small · Not hot path (no caller; mouse-down handler)
Problem
InputField_HitTestCursorloopsi=1..size, each callingGetLineWidth(view(data,i))which re-walks from byte 0 — O(n^2)stbtt_GetCodepointHMetricscalls (each an uncached cmap binary search).Proposed fix
Single left-to-right cumulative-advance prefix-sum, then scan/binary-search.
Correctness caveat
The prefix-sum must be keyed at byte boundaries (cursorPos is byte-based via
value.erase(cursorPos,1)), not per-codepoint. Note: this function currently has no caller in the repo.