walterddr commented on a change in pull request #7487: URL: https://github.com/apache/pinot/pull/7487#discussion_r716776370
########## File path: pinot-spi/src/main/java/org/apache/pinot/spi/utils/ByteArray.java ########## @@ -91,19 +109,55 @@ public int compareTo(@Nonnull ByteArray that) { * <li> +ve integer if first value is larger than the second. </li> * </ul> * - * @param bytes1 First byte[] to compare. - * @param bytes2 Second byte[] to compare. + * @param left First byte[] to compare. + * @param right Second byte[] to compare. + * @return Result of comparison as stated above. + */ + public static int compare(byte[] left, byte[] right) { + return compare(left, 0, left.length, right, 0, right.length); + } + + /** + * Compares two byte[] values. The comparison performed is on unsigned value for each byte. + * Returns: + * <ul> + * <li> 0 if both values are identical. </li> + * <li> -ve integer if first value is smaller than the second. </li> + * <li> +ve integer if first value is larger than the second. </li> + * </ul> + * + * @param left First byte[] to compare. + * @param leftFromIndex inclusive index of first byte to compare in left + * @param leftToIndex exclusive index of last byte to compare in left + * @param right Second byte[] to compare. + * @param rightFromIndex inclusive index of first byte to compare in right + * @param rightToIndex exclusive index of last byte to compare in right * @return Result of comparison as stated above. */ - public static int compare(byte[] bytes1, byte[] bytes2) { - int len1 = bytes1.length; - int len2 = bytes2.length; + public static int compare(byte[] left, int leftFromIndex, int leftToIndex, + byte[] right, int rightFromIndex, int rightToIndex) { + if (COMPARE_UNSIGNED != null) { + try { + return (int) COMPARE_UNSIGNED.invokeExact(left, leftFromIndex, leftToIndex, + right, rightFromIndex, rightToIndex); + } catch (ArrayIndexOutOfBoundsException outOfBounds) { + throw outOfBounds; + } catch (Throwable ignore) { Review comment: can we add tests for the IOE and fallback for JDK9+? -- 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: commits-unsubscr...@pinot.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org --------------------------------------------------------------------- To unsubscribe, e-mail: commits-unsubscr...@pinot.apache.org For additional commands, e-mail: commits-h...@pinot.apache.org