diff options
author | Seigo Nonaka <nona@google.com> | 2021-06-04 16:07:23 -0700 |
---|---|---|
committer | Android Build Coastguard Worker <android-build-coastguard-worker@google.com> | 2021-06-30 05:29:37 +0000 |
commit | dd1863dd3a51da2f09975ec99ed6e057fe525d3e (patch) | |
tree | a7cd4d70100a439c65a07fc41dc2758b96c30504 | |
parent | a6ddce2b3c6046c3356e1e9a70c9791710a69b2d (diff) | |
download | base-dd1863dd3a51da2f09975ec99ed6e057fe525d3e.tar.gz |
Improve ellipsize performance
Instead of iterate all ellipsized characters, only iterate the necessary
ranges for copying.
Bug: 188913943
Test: atest CtsTextTestCases CtsGraphicsTestCases CtsWidgetTestCases
Change-Id: I3d03b1e3897e427c23fbe51315f412c57a4ce9e9
(cherry picked from commit 2c6121f3e3c52965ae33317e4fe7a273fd1742c6)
(cherry picked from commit 0c17ccc4af2b28823a12cf846e9222c3c8b472de)
-rw-r--r-- | core/java/android/text/Layout.java | 9 |
1 files changed, 5 insertions, 4 deletions
diff --git a/core/java/android/text/Layout.java b/core/java/android/text/Layout.java index c02f7ef65a77..3154acccc6d8 100644 --- a/core/java/android/text/Layout.java +++ b/core/java/android/text/Layout.java @@ -2280,7 +2280,10 @@ public abstract class Layout { final int ellipsisStringLen = ellipsisString.length(); // Use the ellipsis string only if there are that at least as many characters to replace. final boolean useEllipsisString = ellipsisCount >= ellipsisStringLen; - for (int i = 0; i < ellipsisCount; i++) { + final int min = Math.max(0, start - ellipsisStart - lineStart); + final int max = Math.min(ellipsisCount, end - ellipsisStart - lineStart); + + for (int i = min; i < max; i++) { final char c; if (useEllipsisString && i < ellipsisStringLen) { c = ellipsisString.charAt(i); @@ -2289,9 +2292,7 @@ public abstract class Layout { } final int a = i + ellipsisStart + lineStart; - if (start <= a && a < end) { - dest[destoff + a - start] = c; - } + dest[destoff + a - start] = c; } } |