From e0e76fd8a60b37dc92c9e3a1b31996a19a71229d Mon Sep 17 00:00:00 2001 From: Googler Date: Wed, 6 Jul 2016 10:16:01 +0000 Subject: Micro-optimizations to Digest.fromMetadata(): Don't encode paths as UTF-8 to md5sum them (the map keys are Strings derived from Paths, for which Fingerprint.addPath() takes the same shortcut). Remove defensive copy from the constructor (which did not need to be public). Remove redundant call to Fingerprint.reset(). -- MOS_MIGRATED_REVID=126682477 --- .../com/google/devtools/build/lib/actions/cache/Digest.java | 11 +++-------- 1 file changed, 3 insertions(+), 8 deletions(-) (limited to 'src/main/java/com/google/devtools/build/lib/actions') diff --git a/src/main/java/com/google/devtools/build/lib/actions/cache/Digest.java b/src/main/java/com/google/devtools/build/lib/actions/cache/Digest.java index 01cf7e1833..c5653ac8fa 100644 --- a/src/main/java/com/google/devtools/build/lib/actions/cache/Digest.java +++ b/src/main/java/com/google/devtools/build/lib/actions/cache/Digest.java @@ -13,9 +13,7 @@ // limitations under the License. package com.google.devtools.build.lib.actions.cache; -import com.google.common.annotations.VisibleForTesting; import com.google.devtools.build.lib.util.Fingerprint; -import com.google.devtools.build.lib.util.Preconditions; import com.google.devtools.build.lib.util.VarInt; import java.io.IOException; @@ -46,10 +44,8 @@ public class Digest { * Construct the digest from the given bytes. * @param digest an MD5 digest. Must be sized properly. */ - @VisibleForTesting - Digest(byte[] digest) { - Preconditions.checkState(digest.length == MD5_SIZE); - this.digest = digest.clone(); + private Digest(byte[] digest) { + this.digest = digest; } /** @@ -88,7 +84,6 @@ public class Digest { Fingerprint fp = new Fingerprint(); for (Map.Entry entry : mdMap.entrySet()) { xorWith(result, getDigest(fp, entry.getKey(), entry.getValue())); - fp.reset(); } return new Digest(result); } @@ -116,7 +111,7 @@ public class Digest { } private static byte[] getDigest(Fingerprint fp, String execPath, Metadata md) { - fp.addString(execPath); + fp.addStringLatin1(execPath); if (md == null) { // Move along, nothing to see here. -- cgit v1.2.3