stream: Optimize `StringIStream.read_all`
authorJean-Christophe Beaupré <jcbrinfo@users.noreply.github.com>
Sat, 20 Dec 2014 21:00:36 +0000 (16:00 -0500)
committerJean-Christophe Beaupré <jcbrinfo@users.noreply.github.com>
Mon, 29 Dec 2014 20:51:21 +0000 (15:51 -0500)
Signed-off-by: Jean-Christophe Beaupré <jcbrinfo@users.noreply.github.com>

lib/standard/stream.nit

index 46ad73c..ddc01fe 100644 (file)
@@ -493,5 +493,12 @@ class StringIStream
                source = ""
        end
 
+       redef fun read_all do
+               var c = cursor
+               cursor = source.length
+               if c == 0 then return source
+               return source.substring_from(c)
+       end
+
        redef fun eof do return cursor >= source.length
 end