diff graal/com.oracle.truffle.sl/src/com/oracle/truffle/sl/builtins/SLReadlnBuiltin.java @ 13882:afd6fa5e8229

SL: Feedback from reviewers
author Christian Wimmer <christian.wimmer@oracle.com>
date Wed, 05 Feb 2014 08:02:15 -0800
parents b16ec83edc73
children abe7128ca473
line wrap: on
line diff
--- a/graal/com.oracle.truffle.sl/src/com/oracle/truffle/sl/builtins/SLReadlnBuiltin.java	Wed Feb 05 15:50:36 2014 +0100
+++ b/graal/com.oracle.truffle.sl/src/com/oracle/truffle/sl/builtins/SLReadlnBuiltin.java	Wed Feb 05 08:02:15 2014 -0800
@@ -24,6 +24,7 @@
 
 import java.io.*;
 
+import com.oracle.truffle.api.CompilerDirectives.SlowPath;
 import com.oracle.truffle.api.dsl.*;
 import com.oracle.truffle.api.nodes.*;
 import com.oracle.truffle.sl.*;
@@ -37,17 +38,22 @@
 
     @Specialization
     public String readln() {
+        String result = doRead(getContext().getInput());
+        if (result == null) {
+            /*
+             * We do not have a sophisticated end of file handling, so returning an empty string is
+             * a reasonable alternative. Note that the Java null value should never be used, since
+             * it can interfere with the specialization logic in generated source code.
+             */
+            result = "";
+        }
+        return result;
+    }
+
+    @SlowPath
+    private static String doRead(BufferedReader in) {
         try {
-            String result = getContext().getInput().readLine();
-            if (result == null) {
-                /*
-                 * We do not have a sophisticated end of file handling, so returning an empty string
-                 * is a reasonable alternative. Note that the Java null value should never be used,
-                 * since it can interfere with the specialization logic in generated source code.
-                 */
-                result = "";
-            }
-            return result;
+            return in.readLine();
         } catch (IOException ex) {
             throw new SLException(ex.getMessage());
         }