OSDN Git Service

TIF: optimize android.media.tv.Tvcontract.Programs.Genres#decode
authorJiabin <jiabin@google.com>
Fri, 19 Feb 2016 06:13:50 +0000 (15:13 +0900)
committerJiabin <jiabin@google.com>
Sat, 20 Feb 2016 05:22:33 +0000 (14:22 +0900)
test result:
 Decode function takes about 0.25 seconds with 1350 channels in Live Channels.
 The original one takes about 0.37 seconds in the same test case.

Bug: 23307587
Change-Id: I3a1fefe0b3e6c1986c8f515259658f2e3e23011f

media/java/android/media/tv/TvContract.java

index 7b8e4b2..1c11842 100644 (file)
@@ -1314,6 +1314,8 @@ public final class TvContract {
             private static final char COMMA = ',';
             private static final String DELIMITER = ",";
 
+            private static final String[] EMPTY_STRING_ARRAY = new String[0];
+
             private Genres() {}
 
             /**
@@ -1359,6 +1361,12 @@ public final class TvContract {
              * @return genre strings.
              */
             public static String[] decode(String genres) {
+                if (genres.isEmpty()) {
+                    return EMPTY_STRING_ARRAY;
+                }
+                if (genres.indexOf(COMMA) == -1 && genres.indexOf(DOUBLE_QUOTE) == -1) {
+                    return new String[] {genres.trim()};
+                }
                 StringBuilder sb = new StringBuilder();
                 List<String> results = new ArrayList<>();
                 int length = genres.length();