zabetak commented on a change in pull request #1080: [CALCITE-2887] Improve 
performance of RelLiteral#toJavaString
URL: https://github.com/apache/calcite/pull/1080#discussion_r261832715
 
 

 ##########
 File path: core/src/main/java/org/apache/calcite/util/Util.java
 ##########
 @@ -481,22 +481,26 @@ public static void print(
    * prints <code>"x\"y"</code>.
    */
   public static void printJavaString(
-      PrintWriter pw,
+      Appendable pw,
       String s,
       boolean nullMeansNull) {
-    if (s == null) {
-      if (nullMeansNull) {
-        pw.print("null");
+    try {
+      if (s == null) {
+        if (nullMeansNull) {
+          pw.append("null");
+        }
+      } else {
+        String s1 = replace(s, "\\", "\\\\");
+        String s2 = replace(s1, "\"", "\\\"");
+        String s3 = replace(s2, "\n\r", "\\n");
+        String s4 = replace(s3, "\n", "\\n");
+        String s5 = replace(s4, "\r", "\\r");
+        pw.append('"');
+        pw.append(s5);
+        pw.append('"');
       }
-    } else {
-      String s1 = replace(s, "\\", "\\\\");
-      String s2 = replace(s1, "\"", "\\\"");
-      String s3 = replace(s2, "\n\r", "\\n");
-      String s4 = replace(s3, "\n", "\\n");
-      String s5 = replace(s4, "\r", "\\r");
-      pw.print("\"");
-      pw.print(s5);
-      pw.print("\"");
+    } catch (IOException ioe) {
+      throw new RuntimeException("Propagates exception in cause.", ioe);
 
 Review comment:
   I didn't know about UncheckedIOException, yes it seems more appropriate. 
Thanks for the pointer :)

----------------------------------------------------------------
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.
 
For queries about this service, please contact Infrastructure at:
[email protected]


With regards,
Apache Git Services

Reply via email to