nizhikov commented on a change in pull request #9665:
URL: https://github.com/apache/ignite/pull/9665#discussion_r771922542
##########
File path:
modules/core/src/main/java/org/apache/ignite/internal/cache/query/index/sorted/keys/BytesCompareUtils.java
##########
@@ -19,41 +19,24 @@
/** */
public final class BytesCompareUtils {
- /** */
- public static int compareNotNullSigned(byte[] arr0, byte[] arr1) {
- if (arr0 == arr1)
- return 0;
- else {
- int commonLen = Math.min(arr0.length, arr1.length);
-
- for (int i = 0; i < commonLen; ++i) {
- byte b0 = arr0[i];
- byte b1 = arr1[i];
-
- if (b0 != b1)
- return b0 > b1 ? 1 : -1;
- }
-
- return Integer.signum(arr0.length - arr1.length);
- }
- }
-
/** */
public static int compareNotNullUnsigned(byte[] arr0, byte[] arr1) {
if (arr0 == arr1)
return 0;
else {
int commonLen = Math.min(arr0.length, arr1.length);
+ int unSignArr0;
+ int unSignArr1;
for (int i = 0; i < commonLen; ++i) {
- int unSignArr0 = arr0[i] & 255;
- int unSignArr1 = arr1[i] & 255;
+ unSignArr0 = arr0[i] & 255;
+ unSignArr1 = arr1[i] & 255;
if (unSignArr0 != unSignArr1)
return unSignArr0 > unSignArr1 ? 1 : -1;
}
- return Integer.signum(arr0.length - arr1.length);
+ return Integer.signum(Integer.compare(arr0.length, arr1.length));
Review comment:
`compare` contract doen't guarantee that only `-1, 0, 1` will be
returned.
But logic inside index subsystem distinguish -1 and -2 results of comparison.
`Integer.signum` required to make sure that only expected values returned.
--
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]