Presize the inputs array when reading an action cache entry.
This generally saves at least one copy.
Closes
@@ -418,7 +418,9 @@ public class CompactPersistentActionCache implements ActionCache {
Md5Digest md5Digest = DigestUtils.read(source);
int count = VarInt.getVarInt(source);
- ImmutableList.Builder<String> builder = new ImmutableList.Builder<>();
+ ImmutableList<String> files = null;
+ if (count != NO_INPUT_DISCOVERY_COUNT) {
+ ImmutableList.Builder<String> builder = ImmutableList.builderWithExpectedSize(count);
for (int i = 0; i < count; i++) {
int id = VarInt.getVarInt(source);
String filename = (id >= 0 ? indexer.getStringForIndex(id) : null);
@@ -427,17 +429,15 @@ public class CompactPersistentActionCache implements ActionCache {
}
builder.add(filename);
}
+ files = builder.build();
+ }
Md5Digest usedClientEnvDigest = DigestUtils.read(source);
if (source.remaining() > 0) {
throw new IOException("serialized entry data has not been fully decoded");
}
- return new ActionCache.Entry(
- actionKey,
- usedClientEnvDigest,
- count == NO_INPUT_DISCOVERY_COUNT ? null : builder.build(),
- md5Digest);
+ return new ActionCache.Entry(actionKey, usedClientEnvDigest, files, md5Digest);
} catch (BufferUnderflowException e) {
throw new IOException("encoded entry data is incomplete", e);
}
