dbatomic commented on code in PR #45816:
URL: https://github.com/apache/spark/pull/45816#discussion_r1553766107
##########
common/unsafe/src/main/java/org/apache/spark/unsafe/types/UTF8String.java:
##########
@@ -447,28 +442,50 @@ private UTF8String toUpperCaseSlow() {
return fromString(toString().toUpperCase());
}
+ /**
+ * Optimized lowercase comparison for UTF8_BINARY_LCASE collation
+ */
+ public int compareLowercase(UTF8String other) {
+ int curr;
+ for (curr = 0; curr < numBytes && curr < other.numBytes; curr++) {
+ byte left, right;
+ if ((left = getByte(curr)) < 0 || (right = other.getByte(curr)) < 0) {
+ return compareLowercaseSuffixSlow(other, curr);
+ }
+ int lowerLeft = Character.toLowerCase(left);
+ int lowerRight = Character.toLowerCase(right);
+ if (lowerLeft != lowerRight) {
+ return lowerLeft - lowerRight;
+ }
+ }
+ return numBytes - other.numBytes;
+ }
+
+ private int compareLowercaseSuffixSlow(UTF8String other, int pref) {
+ UTF8String suffixLeft = UTF8String.fromAddress(base, offset + pref,
+ numBytes - pref);
+ UTF8String suffixRight = UTF8String.fromAddress(other.base, other.offset +
pref,
+ other.numBytes - pref);
+ return
suffixLeft.toLowerCaseSlow().binaryCompare(suffixRight.toLowerCaseSlow());
+ }
+
/**
* Returns the lower case of this string
*/
public UTF8String toLowerCase() {
if (numBytes == 0) {
return EMPTY_UTF8;
}
-
- byte[] bytes = new byte[numBytes];
- bytes[0] = (byte) Character.toTitleCase(getByte(0));
+ // skip allocation if we need to fallback
Review Comment:
Better than saying "skip allocation" explain why we need fallback here.
--
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]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]