Add shortcut that identity-equal lists/objects are equals()

The intent here is to make it fast to compare something
to itself. Though maybe Java does this automatically,
not sure.
This commit is contained in:
Havoc Pennington 2014-07-07 21:19:09 -04:00
parent 66d21576b1
commit fdce50fb76
4 changed files with 9 additions and 4 deletions

View File

@ -233,7 +233,8 @@ final class ConfigDelayedMerge extends AbstractConfigValue implements Unmergeabl
// note that "origin" is deliberately NOT part of equality
if (other instanceof ConfigDelayedMerge) {
return canEqual(other)
&& this.stack.equals(((ConfigDelayedMerge) other).stack);
&& (this.stack == ((ConfigDelayedMerge) other).stack || this.stack
.equals(((ConfigDelayedMerge) other).stack));
} else {
return false;
}

View File

@ -170,8 +170,8 @@ final class ConfigDelayedMergeObject extends AbstractConfigObject implements Unm
// note that "origin" is deliberately NOT part of equality
if (other instanceof ConfigDelayedMergeObject) {
return canEqual(other)
&& this.stack
.equals(((ConfigDelayedMergeObject) other).stack);
&& (this.stack == ((ConfigDelayedMergeObject) other).stack || this.stack
.equals(((ConfigDelayedMergeObject) other).stack));
} else {
return false;
}

View File

@ -154,7 +154,8 @@ final class SimpleConfigList extends AbstractConfigValue implements ConfigList,
// note that "origin" is deliberately NOT part of equality
if (other instanceof SimpleConfigList) {
// optimization to avoid unwrapped() for two ConfigList
return canEqual(other) && value.equals(((SimpleConfigList) other).value);
return canEqual(other)
&& (value == ((SimpleConfigList) other).value || value.equals(((SimpleConfigList) other).value));
} else {
return false;
}

View File

@ -443,6 +443,9 @@ final class SimpleConfigObject extends AbstractConfigObject implements Serializa
}
private static boolean mapEquals(Map<String, ConfigValue> a, Map<String, ConfigValue> b) {
if (a == b)
return true;
Set<String> aKeys = a.keySet();
Set<String> bKeys = b.keySet();