You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@calcite.apache.org by GitBox <gi...@apache.org> on 2019/03/01 17:58:03 UTC

[GitHub] asereda-gs commented on a change in pull request #1080: [CALCITE-2887] Improve performance of RelLiteral#toJavaString

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

 ##########
 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:
   Perhaps [UncheckedIOException](https://docs.oracle.com/javase/8/docs/api/java/io/UncheckedIOException.html) is better in this case ? 

----------------------------------------------------------------
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:
users@infra.apache.org


With regards,
Apache Git Services