JoshRosen commented on code in PR #46894:
URL: https://github.com/apache/spark/pull/46894#discussion_r1630716297
##########
sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/catalog/ExternalCatalogUtils.scala:
##########
@@ -63,25 +63,35 @@ object ExternalCatalogUtils {
bitSet
}
- 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 builder = new StringBuilder()
- path.foreach { c =>
- if (needsEscaping(c)) {
- builder.append('%')
- builder.append(f"${c.asInstanceOf[Int]}%02X")
- } else {
- builder.append(c)
+ var firstIndex = 0
+ val length = path.length
+ while (firstIndex < length && !needsEscaping(path.charAt(firstIndex))) {
+ firstIndex += 1
+ }
+ if (firstIndex == 0) {
+ path
+ } else {
+ val sb = new StringBuilder(path.substring(0, firstIndex))
Review Comment:
I think there's two potential optimizations that we can do for the
StringBuilder here:
1. use `java.lang.StringBuilder`, since Scala's StringBuilder is just a
wrapper over it.
2. since the output string is at least as long as the input string, pre-size
the builder to avoid having to resize it while we're traversing over the rest
of the string
```suggestion
val sb = new java.lang.StringBuilder(length + 16)
sb.append(path.substring(0, firstIndex))
```
--
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]