RefDirectory: Look up several exact refs in one shot
Override exactRef(String...) and firstExactRef(String...) with implementations specific to FileRepository. The specialized implementations are similar to the generic ones from RefDatabase, but because these use readRef directly instead of exactRef, they only need to call fireRefsChanged once. This will allow replacing RefDirectory#getRef with a generic implementation that uses firstExactRef without hurting performance. Change-Id: I1be1948bd6121c1a1e8152e201aab97e7fb308bb Signed-off-by: Jonathan Nieder <jrn@google.com>
This commit is contained in:
parent
b2ec6405e4
commit
d2bab65470
|
@ -74,6 +74,7 @@
|
|||
import java.util.Arrays;
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import java.util.HashMap;
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
@ -350,6 +351,43 @@ public Ref exactRef(String name) throws IOException {
|
|||
}
|
||||
}
|
||||
|
||||
/** {@inheritDoc} */
|
||||
@Override
|
||||
@NonNull
|
||||
public Map<String, Ref> exactRef(String... refs) throws IOException {
|
||||
try {
|
||||
RefList<Ref> packed = getPackedRefs();
|
||||
Map<String, Ref> result = new HashMap<>(refs.length);
|
||||
for (String name : refs) {
|
||||
Ref ref = readAndResolve(name, packed);
|
||||
if (ref != null) {
|
||||
result.put(name, ref);
|
||||
}
|
||||
}
|
||||
return result;
|
||||
} finally {
|
||||
fireRefsChanged();
|
||||
}
|
||||
}
|
||||
|
||||
/** {@inheritDoc} */
|
||||
@Override
|
||||
@Nullable
|
||||
public Ref firstExactRef(String... refs) throws IOException {
|
||||
try {
|
||||
RefList<Ref> packed = getPackedRefs();
|
||||
for (String name : refs) {
|
||||
Ref ref = readAndResolve(name, packed);
|
||||
if (ref != null) {
|
||||
return ref;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
} finally {
|
||||
fireRefsChanged();
|
||||
}
|
||||
}
|
||||
|
||||
/** {@inheritDoc} */
|
||||
@Override
|
||||
public Ref getRef(String needle) throws IOException {
|
||||
|
|
Loading…
Reference in New Issue