You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@pinot.apache.org by GitBox <gi...@apache.org> on 2021/09/27 14:16:33 UTC

[GitHub] [pinot] richardstartin commented on a change in pull request #7487: use MethodHandle to access vectorized unsigned comparison on JDK9+

richardstartin commented on a change in pull request #7487:
URL: https://github.com/apache/pinot/pull/7487#discussion_r716736347



##########
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:
       it can't happen, it's just a consequence of the API. Propagating `ArrayIndexOutOfBoundsException` is important though.




-- 
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-unsubscribe@pinot.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@pinot.apache.org
For additional commands, e-mail: commits-help@pinot.apache.org