From c49999b9334b68433db0cd60ef391fd70cb00c0b Mon Sep 17 00:00:00 2001 From: Florian Schmaus Date: Mon, 13 Apr 2020 20:01:20 +0200 Subject: [PATCH] core: add shortcut via hash in EqualsUtil Return false as soon as the hashed value does not match. This is sound, since every class that implements equals(Object) should also implement hashCode(). --- .../main/java/org/jivesoftware/smack/util/EqualsUtil.java | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/smack-core/src/main/java/org/jivesoftware/smack/util/EqualsUtil.java b/smack-core/src/main/java/org/jivesoftware/smack/util/EqualsUtil.java index 9d786cc8f..8110358a7 100644 --- a/smack-core/src/main/java/org/jivesoftware/smack/util/EqualsUtil.java +++ b/smack-core/src/main/java/org/jivesoftware/smack/util/EqualsUtil.java @@ -1,6 +1,6 @@ /** * - * Copyright 2019 Florian Schmaus. + * Copyright 2019-2020 Florian Schmaus. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -34,6 +34,12 @@ public final class EqualsUtil { return false; } + int thisHashCode = thisObject.hashCode(); + int otherHashCode = other.hashCode(); + if (thisHashCode != otherHashCode) { + return false; + } + EqualsUtil.Builder equalsBuilder = new EqualsUtil.Builder(); equalsComperator.compare(equalsBuilder, thisObjectClass.cast(other));