keith-turner commented on code in PR #2811:
URL: https://github.com/apache/accumulo/pull/2811#discussion_r978075208
##########
core/src/main/java/org/apache/accumulo/core/data/Key.java:
##########
@@ -975,30 +981,26 @@ public void write(DataOutput out) throws IOException {
* @return true if specified parts of keys match, false otherwise
*/
public boolean equals(Key other, PartialKey part) {
- switch (part) {
- case ROW:
- return isEqual(row, other.row);
- case ROW_COLFAM:
- return isEqual(row, other.row) && isEqual(colFamily, other.colFamily);
- case ROW_COLFAM_COLQUAL:
- return isEqual(row, other.row) && isEqual(colFamily, other.colFamily)
- && isEqual(colQualifier, other.colQualifier);
- case ROW_COLFAM_COLQUAL_COLVIS:
- return isEqual(row, other.row) && isEqual(colFamily, other.colFamily)
- && isEqual(colQualifier, other.colQualifier)
- && isEqual(colVisibility, other.colVisibility);
- case ROW_COLFAM_COLQUAL_COLVIS_TIME:
- return isEqual(row, other.row) && isEqual(colFamily, other.colFamily)
- && isEqual(colQualifier, other.colQualifier)
- && isEqual(colVisibility, other.colVisibility) && timestamp ==
other.timestamp;
- case ROW_COLFAM_COLQUAL_COLVIS_TIME_DEL:
- return isEqual(row, other.row) && isEqual(colFamily, other.colFamily)
- && isEqual(colQualifier, other.colQualifier)
- && isEqual(colVisibility, other.colVisibility) && timestamp ==
other.timestamp
- && deleted == other.deleted;
- default:
- throw new IllegalArgumentException("Unrecognized partial key
specification " + part);
- }
+ boolean result = isEqual(row, other.row);
+ if (part == ROW)
+ return result;
+ result &= isEqual(colFamily, other.colFamily);
+ if (part == ROW_COLFAM)
+ return result;
+ result &= isEqual(colQualifier, other.colQualifier);
+ if (part == ROW_COLFAM_COLQUAL)
+ return result;
+ result &= isEqual(colVisibility, other.colVisibility);
+ if (part == ROW_COLFAM_COLQUAL_COLVIS)
+ return result;
+ result &= (timestamp == other.timestamp);
+ if (part == ROW_COLFAM_COLQUAL_COLVIS_TIME)
+ return result;
+ result &= (deleted == other.deleted);
+ if (part == ROW_COLFAM_COLQUAL_COLVIS_TIME_DEL)
Review Comment:
The way the code was written before it would short circuit. Like in the old
code if the rows were not equal it would not do any comparisons after that. In
the new code when the rows are not equal it still compares the rest of the
fields. Seems like this could really make a difference for some data. Not sure
we should manually short circuit because I don't know how that would compare to
what the compiler does.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]