rednaxelafx commented on a change in pull request #23406: [SPARK-26504][SQL]
Rope-wise dumping of Spark plans
URL: https://github.com/apache/spark/pull/23406#discussion_r244550383
##########
File path:
sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/util/StringUtils.scala
##########
@@ -87,4 +89,34 @@ object StringUtils {
}
funcNames.toSeq
}
+
+ /**
+ * Concatenation of sequence of strings to final string with cheap append
method
+ * and one memory allocation for the final string.
+ */
+ class StringConcat {
+ private val strings = new ArrayBuffer[String]
+ private var length: Int = 0
+
+ /**
+ * Appends a string and accumulates its length to allocate a string buffer
for all
+ * appended strings once in the toString method.
+ */
+ def append(s: String): Unit = {
+ if (s != null) {
+ strings.append(s)
+ length += s.length
+ }
+ }
+
+ /**
+ * The method allocates memory for all appended strings, writes them to
the memory and
+ * returns concatenated string.
+ */
+ override def toString: String = {
+ val result = new StringBuffer(length)
Review comment:
Can we just use `java.lang.StringBuilder` here for the sake of reducing one
useless allocation of the Scala wrapper?
Which `StringBuffer` is this anyway? If you're using the Scala
scala.collection.mutable.*, it should have been `StringBuilder`, right?
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
[email protected]
With regards,
Apache Git Services
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]