Skip to content

Commit

Permalink
Presize the inputs array when reading an action cache entry.
Browse files Browse the repository at this point in the history
This generally saves at least one copy.

Closes #6181.

PiperOrigin-RevId: 214382842
  • Loading branch information
benjaminp authored and Copybara-Service committed Sep 25, 2018
1 parent d65ed23 commit 1e68ace
Showing 1 changed file with 12 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -418,26 +418,26 @@ private static ActionCache.Entry decode(StringIndexer indexer, byte[] data) thro
Md5Digest md5Digest = DigestUtils.read(source);

int count = VarInt.getVarInt(source);
ImmutableList.Builder<String> builder = new ImmutableList.Builder<>();
for (int i = 0; i < count; i++) {
int id = VarInt.getVarInt(source);
String filename = (id >= 0 ? indexer.getStringForIndex(id) : null);
if (filename == null) {
throw new IOException("Corrupted file index");
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);
if (filename == null) {
throw new IOException("Corrupted file index");
}
builder.add(filename);
}
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);
}
Expand Down

0 comments on commit 1e68ace

Please sign in to comment.