1
0
Fork 0
mirror of https://codeberg.org/Mercury-IM/Smack synced 2024-11-22 06:12:05 +01:00

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().
This commit is contained in:
Florian Schmaus 2020-04-13 20:01:20 +02:00
parent 4f609b855c
commit c49999b933

View file

@ -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));