From 5d015d7331923f852a2a8675b4203b29f6c34d96 Mon Sep 17 00:00:00 2001 From: Bjorn Bringert <> Date: Thu, 2 Apr 2009 09:00:58 -0700 Subject: [PATCH] AI 144010: am: CL 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. Original author: bringert Merged from: //branches/donutburger/... Automated import of CL 144010 --- core/java/android/content/UriMatcher.java | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/core/java/android/content/UriMatcher.java b/core/java/android/content/UriMatcher.java index a98e6d57eed81..c28ecac22ea4b 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 pathSegments = uri.getPathSegments(); + final int li = pathSegments.size(); UriMatcher node = this; @@ -209,7 +210,7 @@ public class UriMatcher } for (int i=-1; i list = node.mChildren; if (list == null) { break;