summaryrefslogtreecommitdiff
path: root/rs/java/android/renderscript/ProgramFragmentFixedFunction.java
diff options
context:
space:
mode:
authorMihai Popa <popam@google.com>2018-05-09 17:31:48 +0100
committerMihai Popa <popam@google.com>2018-05-31 17:16:52 +0100
commit97c613bb2b69636c254db6234582a6c7566e39a6 (patch)
tree5a19f2e24a507ce8e22db9a100271a8d5f6673fd /rs/java/android/renderscript/ProgramFragmentFixedFunction.java
parent459888be84a1a351ab906d23834e8f6661f8ed0b (diff)
Optimise the hit test algorithm
Layout#getOffsetForHorizontal was running in O(n^2) time, where n is the length of the current line. The method is used when a touch event happens on a text line, to compute the cursor offset (and the character) where it happened. Although this is not an issue in common usecases, where the number of characters on a line is relatively small, this can be very inefficient as a consequence of Unicode containing 0-width (invisible) characters. Specifically, there are characters defining the text direction (LTR or RTL), which cause our algorithm to touch the worst case quadratic runtime. For example, a person is able to send a message containing a few visible characters, and also a lot of these direction changing invisible ones. When the receiver touches the message (causing the Layout#getOffsetForHorizontal method to be called), the receiver's application would become not responsive. This CL optimizes the method to run in O(n) worst case. This is achieved by computing the measurements of all line prefixes at first, which can be done in a single pass. Then, all the prefix measurement queries will be answered in O(1), rather than O(n) as it was happening before. Bug: 79215201 Test: manual testing Change-Id: Ib66ef392c19c937718e7101f6d48fac3abe51ad0 Merged-In: Ib66ef392c19c937718e7101f6d48fac3abe51ad0
Diffstat (limited to 'rs/java/android/renderscript/ProgramFragmentFixedFunction.java')
0 files changed, 0 insertions, 0 deletions