JoshRosen commented on code in PR #46894:
URL: https://github.com/apache/spark/pull/46894#discussion_r1630714167
##########
sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/catalog/ExternalCatalogUtils.scala:
##########
@@ -63,29 +63,35 @@ object ExternalCatalogUtils {
bitSet
}
- @inline private final def needsEscaping(c: Char): Boolean = {
+ private final val HEX_CHARS = "0123456789ABCDEF".toCharArray
+
+ @inline final def needsEscaping(c: Char): Boolean = {
c < charToEscape.size() && charToEscape.get(c)
}
def escapePathName(path: String): String = {
- val firstIndex = path.indexWhere(needsEscaping)
- if (firstIndex == -1) {
+ var firstIndex = 0
+ val length = path.length
+ while (firstIndex < length && !needsEscaping(path.charAt(firstIndex))) {
+ firstIndex += 1
+ }
+ if (firstIndex == 0) {
path
} else {
- val builder = new StringBuilder(path.substring(0, firstIndex))
- path.substring(firstIndex).foreach { c =>
+ val sb = new StringBuilder(path.substring(0, firstIndex))
+ while(firstIndex < length) {
+ val c = path.charAt(firstIndex)
if (needsEscaping(c)) {
- builder.append('%')
- builder.append(f"${c.asInstanceOf[Int]}%02X")
+ sb.append('%').append(HEX_CHARS((c & 0xF0) >> 4)).append(HEX_CHARS(c
& 0x0F))
Review Comment:
+1 for performing the hex conversion this way, since the old string
formatting was really really expensive:
<img width="1279" alt="image"
src="https://github.com/apache/spark/assets/50748/285e1a9e-d352-4e62-b70a-b753e3a91aa1">
--
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]