Use hand written hasCode for ChangeIdStateQuery

Because Objects.hash(Object... values) will always create an array
to wrap the "..." arguments, with additional auto-boxing for all
primitive type arguments.

This can reduce the execution time of ChangeIdStateQuery#hashCode()
by 8 times, which is usually the main cost of
CompatChanges#isChangeEnabled.

Bug: 208449209
Test: atest android.app.compat.CompatChangesTest

Change-Id: I863aa1d35e7448b5a965368272198c4529253ae0
This commit is contained in:
Riddle Hsu
2021-12-16 18:12:34 +08:00
parent 9975e2c412
commit 2ad85f0323

View File

@@ -85,6 +85,14 @@ final class ChangeIdStateQuery {
@Override
public int hashCode() {
return Objects.hash(type, changeId, packageName, uid, userId);
int result = 1;
result = 31 * result + type;
result = 31 * result + (int) (changeId ^ (changeId >>> 32));
if (packageName != null) {
result = 31 * result + packageName.hashCode();
}
result = 31 * result + uid;
result = 31 * result + userId;
return result;
}
}