diff options
author | Bjorn Bringert <> | 2009-04-01 10:27:37 -0700 |
---|---|---|
committer | The Android Open Source Project <initial-contribution@android.com> | 2009-04-01 10:27:37 -0700 |
commit | dc0ec1866556c6132c9dd2e6dfaef9306784d955 (patch) | |
tree | 5b41dbbb2644b74d50a3a971d6a7ce92649dab1d /core/java | |
parent | 43f503fd1e042f64994274b3842d8c5979763c23 (diff) | |
download | frameworks_base-dc0ec1866556c6132c9dd2e6dfaef9306784d955.zip frameworks_base-dc0ec1866556c6132c9dd2e6dfaef9306784d955.tar.gz frameworks_base-dc0ec1866556c6132c9dd2e6dfaef9306784d955.tar.bz2 |
AI 144008: UriMatcher: Avoid repeated calls to Uri.getPathSegments()
in UriMatcher.match().
Before, every call to UriMatcher.match() called
Uri.getPathSegments() N + 1 times,
where N is the size of the list returned by
Uri.getPathSegments(). Since some of the implementations
of Uri.getPathSegments() are O(N), UriMatcher.match() was O(N^2).
This CL fixes the problem by calling uri.getPathSegments() once in
the beginning of match(). That should be safe since Uri is
immutable.
BUG=1751158
Automated import of CL 144008
Diffstat (limited to 'core/java')
-rw-r--r-- | core/java/android/content/UriMatcher.java | 5 |
1 files changed, 3 insertions, 2 deletions
diff --git a/core/java/android/content/UriMatcher.java b/core/java/android/content/UriMatcher.java index a98e6d5..c28ecac 100644 --- a/core/java/android/content/UriMatcher.java +++ b/core/java/android/content/UriMatcher.java @@ -200,7 +200,8 @@ public class UriMatcher */ public int match(Uri uri) { - final int li = uri.getPathSegments().size(); + final List<String> pathSegments = uri.getPathSegments(); + final int li = pathSegments.size(); UriMatcher node = this; @@ -209,7 +210,7 @@ public class UriMatcher } for (int i=-1; i<li; i++) { - String u = i < 0 ? uri.getAuthority() : uri.getPathSegments().get(i); + String u = i < 0 ? uri.getAuthority() : pathSegments.get(i); ArrayList<UriMatcher> list = node.mChildren; if (list == null) { break; |