hvanhovell 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_r244539485
 
 

 ##########
 File path: 
sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/util/StringUtils.scala
 ##########
 @@ -87,4 +89,35 @@ 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 StringRope {
+    private val rope = 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) {
+        rope.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 buffer = new StringBuffer(length)
+
 
 Review comment:
   Why the new line?

----------------------------------------------------------------
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]

Reply via email to