commit | 8df27e68fe535e205eb37f950c9fa09b9060f070 | [log] [tgz] |
---|---|---|
author | Thomas Draebing <thomas.draebing@sap.com> | Tue Sep 14 10:29:14 2021 +0200 |
committer | Thomas Draebing <thomas.draebing@sap.com> | Tue Sep 21 15:01:19 2021 +0200 |
tree | 336aea84b34ad250ad12a5b806b1155522c1f811 | |
parent | c903642f36ac663f8b7efc5abad6b055c459c283 [diff] |
Memoize methods of ExternalId and ExternalId.Key The results of the following methods does not change: - ExternalId.toString() - ExternalId.Key.sha1() - ExternalId.Key.hashCode() AutoValue provides the @Memoized annotation [1]. With it the return value will be stored and not computed again. [1] https://github.com/google/auto/blob/master/value/userguide/howto.md#-memoize-the-result-of-hashcode-or-tostring Change-Id: Iad599d3351934f746e4cfcc9357697538e5eaaa4
diff --git a/java/com/google/gerrit/server/account/externalids/ExternalId.java b/java/com/google/gerrit/server/account/externalids/ExternalId.java index 8bf095c..30f4094 100644 --- a/java/com/google/gerrit/server/account/externalids/ExternalId.java +++ b/java/com/google/gerrit/server/account/externalids/ExternalId.java
@@ -191,6 +191,7 @@ * notes branch. */ @SuppressWarnings("deprecation") // Use Hashing.sha1 for compatibility. + @Memoized public ObjectId sha1() { String keyString = isCaseInsensitive() ? get().toLowerCase(Locale.US) : get(); return ObjectId.fromRaw(Hashing.sha1().hashString(keyString, UTF_8).asBytes()); @@ -226,7 +227,8 @@ } @Override - public final int hashCode() { + @Memoized + public int hashCode() { return Objects.hash(sha1()); } @@ -322,7 +324,8 @@ * </pre> */ @Override - public final String toString() { + @Memoized + public String toString() { Config c = new Config(); writeToConfig(c); return c.toText();