From 28adcce8622814e6b0ecb33168eae1846829390d Mon Sep 17 00:00:00 2001 From: Dave Borowitz Date: Wed, 5 Jul 2017 09:57:01 -0400 Subject: [PATCH] BatchRefUpdate: Clarify some ref prefix calls Inline the old addRefToPrefixes, since it was just a glorified addAll. Split getPrefixes into a variant, addPrefixesTo, that doesn't allocate a small Collection on every invocation. Use this in the tight loop of getTakenPrefixes. Change-Id: I25cc7feef0c8e312820d85b7ed48559da49b83d2 --- .../org/eclipse/jgit/lib/BatchRefUpdate.java | 25 ++++++++----------- 1 file changed, 11 insertions(+), 14 deletions(-) diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/lib/BatchRefUpdate.java b/org.eclipse.jgit/src/org/eclipse/jgit/lib/BatchRefUpdate.java index 3f6995de83..3043d4fcda 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/lib/BatchRefUpdate.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/lib/BatchRefUpdate.java @@ -462,7 +462,7 @@ public class BatchRefUpdate { break SWITCH; } ru.setCheckConflicting(false); - addRefToPrefixes(takenPrefixes, cmd.getRefName()); + takenPrefixes.addAll(getPrefixes(cmd.getRefName())); takenNames.add(cmd.getRefName()); cmd.setResult(ru.update(walk)); } @@ -523,29 +523,26 @@ public class BatchRefUpdate { execute(walk, monitor, null); } - private static Collection getTakenPrefixes( - final Collection names) { + private static Collection getTakenPrefixes(Collection names) { Collection ref = new HashSet<>(); - for (String name : names) - ref.addAll(getPrefixes(name)); - return ref; - } - - private static void addRefToPrefixes(Collection prefixes, - String name) { - for (String prefix : getPrefixes(name)) { - prefixes.add(prefix); + for (String name : names) { + addPrefixesTo(name, ref); } + return ref; } static Collection getPrefixes(String s) { Collection ret = new HashSet<>(); + addPrefixesTo(s, ret); + return ret; + } + + static void addPrefixesTo(String s, Collection out) { int p1 = s.indexOf('/'); while (p1 > 0) { - ret.add(s.substring(0, p1)); + out.add(s.substring(0, p1)); p1 = s.indexOf('/', p1 + 1); } - return ret; } /** -- 2.39.5