OSDN Git Service

Small optimization when getting the spans
authorFabrice Di Meglio <fdimeglio@google.com>
Tue, 15 Feb 2011 22:31:26 +0000 (14:31 -0800)
committerFabrice Di Meglio <fdimeglio@google.com>
Tue, 15 Feb 2011 22:31:26 +0000 (14:31 -0800)
- loop earlier if the kind is not the one we want

Change-Id: I5b020f20a144678ad2f7a4bca8fef64eb6ae491f

core/java/android/text/SpannableStringInternal.java

index 0412285..0825bf3 100644 (file)
@@ -212,6 +212,10 @@ import java.lang.reflect.Array;
         Object ret1 = null;
 
         for (int i = 0; i < spanCount; i++) {
+            if (kind != null && !kind.isInstance(spans[i])) {
+                continue;
+            }
+
             int spanStart = data[i * COLUMNS + START];
             int spanEnd = data[i * COLUMNS + END];
 
@@ -231,10 +235,6 @@ import java.lang.reflect.Array;
                 }
             }
 
-            if (kind != null && !kind.isInstance(spans[i])) {
-                continue;
-            }
-
             if (count == 0) {
                 ret1 = spans[i];
                 count++;