Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit dc0ec186 authored by Bjorn Bringert's avatar Bjorn Bringert Committed by The Android Open Source Project
Browse files

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
parent 43f503fd
Loading
Loading
Loading
Loading
+3 −2
Original line number Diff line number Diff line
@@ -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;