Skip to content

Commit

Permalink
Optimize compareNotNull and compareNotNullSigned Methods in BitsSubst…
Browse files Browse the repository at this point in the history
…itution Class (#9379)

* Optimize compareNotNull method in BitsSubstitution class.

* Optimize compareNotNullSigned method in BitsSubstitution class.
  • Loading branch information
abdelhak-zaaim authored Oct 19, 2024
1 parent 90eb0a2 commit 525ad96
Showing 1 changed file with 15 additions and 7 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2020 Oracle and/or its affiliates.
* Copyright (c) 2020, 2024 Oracle and/or its affiliates.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -53,15 +53,19 @@ public static int compareNotNull(char[] data1, char[] data2) {
if (data1 == data2) {
return 0;
}
int len = Math.min(data1.length, data2.length);
for (int i = 0; i < len; i++) {
int len1 = data1.length;
int len2 = data2.length;
if (len1 != len2) {
return len1 > len2 ? 1 : -1;
}
for (int i = 0; i < len1; i++) {
char b = data1[i];
char b2 = data2[i];
if (b != b2) {
return b > b2 ? 1 : -1;
}
}
return Integer.signum(data1.length - data2.length);
return 0;
}

/**
Expand All @@ -86,15 +90,19 @@ public static int compareNotNullSigned(byte[] data1, byte[] data2) {
if (data1 == data2) {
return 0;
}
int len = Math.min(data1.length, data2.length);
for (int i = 0; i < len; i++) {
int len1 = data1.length;
int len2 = data2.length;
if (len1 != len2) {
return len1 > len2 ? 1 : -1;
}
for (int i = 0; i < len1; i++) {
byte b = data1[i];
byte b2 = data2[i];
if (b != b2) {
return b > b2 ? 1 : -1;
}
}
return Integer.signum(data1.length - data2.length);
return 0;
}

/**
Expand Down

0 comments on commit 525ad96

Please sign in to comment.