am eb189d39: Merge "Performance improvement in TextView" into ics-mr1
* commit 'eb189d399a459c2e1ad29e1beba70d1de9f447b3': Performance improvement in TextView
This commit is contained in:
@@ -119,6 +119,7 @@ class TextLine {
|
|||||||
* @param hasTabs true if the line might contain tabs or emoji
|
* @param hasTabs true if the line might contain tabs or emoji
|
||||||
* @param tabStops the tabStops. Can be null.
|
* @param tabStops the tabStops. Can be null.
|
||||||
*/
|
*/
|
||||||
|
@SuppressWarnings("null")
|
||||||
void set(TextPaint paint, CharSequence text, int start, int limit, int dir,
|
void set(TextPaint paint, CharSequence text, int start, int limit, int dir,
|
||||||
Directions directions, boolean hasTabs, TabStops tabStops) {
|
Directions directions, boolean hasTabs, TabStops tabStops) {
|
||||||
mPaint = paint;
|
mPaint = paint;
|
||||||
@@ -134,11 +135,12 @@ class TextLine {
|
|||||||
mSpanned = null;
|
mSpanned = null;
|
||||||
|
|
||||||
boolean hasReplacement = false;
|
boolean hasReplacement = false;
|
||||||
|
SpanSet<ReplacementSpan> replacementSpans = null;
|
||||||
if (text instanceof Spanned) {
|
if (text instanceof Spanned) {
|
||||||
mSpanned = (Spanned) text;
|
mSpanned = (Spanned) text;
|
||||||
ReplacementSpan[] spans = mSpanned.getSpans(start, limit, ReplacementSpan.class);
|
replacementSpans = new SpanSet<ReplacementSpan>(mSpanned, start, limit,
|
||||||
spans = TextUtils.removeEmptySpans(spans, mSpanned, ReplacementSpan.class);
|
ReplacementSpan.class);
|
||||||
hasReplacement = spans.length > 0;
|
hasReplacement = replacementSpans.numberOfSpans > 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
mCharsValid = hasReplacement || hasTabs || directions != Layout.DIRS_ALL_LEFT_TO_RIGHT;
|
mCharsValid = hasReplacement || hasTabs || directions != Layout.DIRS_ALL_LEFT_TO_RIGHT;
|
||||||
@@ -156,10 +158,9 @@ class TextLine {
|
|||||||
// zero-width characters.
|
// zero-width characters.
|
||||||
char[] chars = mChars;
|
char[] chars = mChars;
|
||||||
for (int i = start, inext; i < limit; i = inext) {
|
for (int i = start, inext; i < limit; i = inext) {
|
||||||
inext = mSpanned.nextSpanTransition(i, limit, ReplacementSpan.class);
|
// replacementSpans cannot be null if hasReplacement is true
|
||||||
ReplacementSpan[] spans = mSpanned.getSpans(i, inext, ReplacementSpan.class);
|
inext = replacementSpans.getNextTransition(i, limit);
|
||||||
spans = TextUtils.removeEmptySpans(spans, mSpanned, ReplacementSpan.class);
|
if (replacementSpans.hasSpansIntersecting(i, inext)) {
|
||||||
if (spans.length > 0) {
|
|
||||||
// transition into a span
|
// transition into a span
|
||||||
chars[i - start] = '\ufffc';
|
chars[i - start] = '\ufffc';
|
||||||
for (int j = i - start + 1, e = inext - start; j < e; ++j) {
|
for (int j = i - start + 1, e = inext - start; j < e; ++j) {
|
||||||
@@ -908,6 +909,15 @@ class TextLine {
|
|||||||
numberOfSpans = count;
|
numberOfSpans = count;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public boolean hasSpansIntersecting(int start, int end) {
|
||||||
|
for (int i = 0; i < numberOfSpans; i++) {
|
||||||
|
// equal test is valid since both intervals are not empty by construction
|
||||||
|
if (spanStarts[i] >= end || spanEnds[i] <= start) continue;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
int getNextTransition(int start, int limit) {
|
int getNextTransition(int start, int limit) {
|
||||||
for (int i = 0; i < numberOfSpans; i++) {
|
for (int i = 0; i < numberOfSpans; i++) {
|
||||||
final int spanStart = spanStarts[i];
|
final int spanStart = spanStarts[i];
|
||||||
|
|||||||
Reference in New Issue
Block a user