PatchSet.isRef()-optimizations. PatchSet.isRef() is used extensively when preparing for a ref advertisment and the regular expression used by isRefs() is notably costly in these circumstances. Even worse, the regular expression cannot be pre-compiled due to lacking RegEx-support in GWT (I guess later GWT versions introduces their own set of RegEx classes, not sure if we want to bring them into PatchSet though). By removing the regular expression and reimplementing the check, we could see upto a 15% performance increase when issuing a git ls-remote. Change-Id: If5a39210dc084bb7cd415cfdb25387657cee2fc7
diff --git a/gerrit-reviewdb/src/main/java/com/google/gerrit/reviewdb/client/PatchSet.java b/gerrit-reviewdb/src/main/java/com/google/gerrit/reviewdb/client/PatchSet.java index 3e4f4f6..54c556d 100644 --- a/gerrit-reviewdb/src/main/java/com/google/gerrit/reviewdb/client/PatchSet.java +++ b/gerrit-reviewdb/src/main/java/com/google/gerrit/reviewdb/client/PatchSet.java
@@ -25,7 +25,27 @@ /** Is the reference name a change reference? */ public static boolean isRef(final String name) { - return name.matches("^refs/changes/.*/[1-9][0-9]*/[1-9][0-9]*$"); + if (name == null || !name.startsWith(REFS_CHANGES)) { + return false; + } + boolean accepted = false; + int numsFound = 0; + for (int i = name.length() - 1; i >= REFS_CHANGES.length() - 1; i--) { + char c = name.charAt(i); + if (c >= '0' && c <= '9') { + accepted = (c != '0'); + } else if (c == '/') { + if (accepted) { + if (++numsFound == 2) { + return true; + } + accepted = false; + } + } else { + return false; + } + } + return false; } public static class Id extends IntKey<Change.Id> {