aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/main/java/com/google/devtools/build/lib/events
diff options
context:
space:
mode:
authorGravatar Ulf Adams <ulfjack@google.com>2016-09-01 08:09:00 +0000
committerGravatar Klaus Aehlig <aehlig@google.com>2016-09-01 08:39:40 +0000
commit8ded9c561985ad91afbfaa4e6f88e16a38c2ea21 (patch)
tree0656be5b5c34d10dab7994120e12b0b381335eb2 /src/main/java/com/google/devtools/build/lib/events
parent602f3ae70f49bd8bae6205a93f3df5918d3bacac (diff)
Cache Event hashcode.
This makes null builds with a lot of events ~50% faster. -- MOS_MIGRATED_REVID=131919322
Diffstat (limited to 'src/main/java/com/google/devtools/build/lib/events')
-rw-r--r--src/main/java/com/google/devtools/build/lib/events/Event.java11
1 files changed, 9 insertions, 2 deletions
diff --git a/src/main/java/com/google/devtools/build/lib/events/Event.java b/src/main/java/com/google/devtools/build/lib/events/Event.java
index 1a74ad2617..3809a8c094 100644
--- a/src/main/java/com/google/devtools/build/lib/events/Event.java
+++ b/src/main/java/com/google/devtools/build/lib/events/Event.java
@@ -30,10 +30,10 @@ import javax.annotation.concurrent.Immutable;
*/
@Immutable
public final class Event implements Serializable {
-
private final EventKind kind;
private final Location location;
private final String message;
+
/**
* An alternative representation for message.
* Exactly one of message or messageBytes will be non-null.
@@ -47,12 +47,15 @@ public final class Event implements Serializable {
@Nullable
private final String tag;
+ private final int hashCode;
+
private Event(EventKind kind, @Nullable Location location, String message, @Nullable String tag) {
this.kind = Preconditions.checkNotNull(kind);
this.location = location;
this.message = Preconditions.checkNotNull(message);
this.messageBytes = null;
this.tag = tag;
+ this.hashCode = Objects.hash(kind, location, message, tag, Arrays.hashCode(messageBytes));
}
private Event(
@@ -62,6 +65,7 @@ public final class Event implements Serializable {
this.message = null;
this.messageBytes = Preconditions.checkNotNull(messageBytes);
this.tag = tag;
+ this.hashCode = Objects.hash(kind, location, message, tag, Arrays.hashCode(messageBytes));
}
public Event withTag(String tag) {
@@ -113,11 +117,14 @@ public final class Event implements Serializable {
@Override
public int hashCode() {
- return Objects.hash(kind, location, message, tag, Arrays.hashCode(messageBytes));
+ return hashCode;
}
@Override
public boolean equals(Object other) {
+ if (other == this) {
+ return true;
+ }
if (other == null || !other.getClass().equals(getClass())) {
return false;
}