lib/file: Remove _buffer.add in stream.read_all
authorLucas Bajolet <r4pass@hotmail.com>
Fri, 14 Aug 2015 16:40:36 +0000 (12:40 -0400)
committerLucas Bajolet <r4pass@hotmail.com>
Fri, 14 Aug 2015 16:40:36 +0000 (12:40 -0400)
Signed-off-by: Lucas Bajolet <r4pass@hotmail.com>

lib/standard/file.nit
lib/standard/stream.nit

index e5fc85b..aba34e8 100644 (file)
@@ -156,7 +156,7 @@ class FileReader
        init open(path: String)
        do
                self.path = path
-               prepare_buffer(10)
+               prepare_buffer(100)
                _file = new NativeFile.io_open_read(path.to_cstring)
                if _file.address_is_null then
                        last_error = new IOError("Cannot open `{path}`: {sys.errno.strerror}")
index ce6e9b3..0eabcba 100644 (file)
@@ -518,14 +518,13 @@ abstract class BufferedReader
        do
                if last_error != null then return new Bytes.empty
                var s = new Bytes.with_capacity(10)
+               var b = _buffer
                while not eof do
                        var j = _buffer_pos
                        var k = _buffer_length
-                       while j < k do
-                               s.add(_buffer[j])
-                               j += 1
-                       end
-                       _buffer_pos = j
+                       var rd_sz = k - j
+                       s.append_ns_from(b, rd_sz, j)
+                       _buffer_pos = k
                        fill_buffer
                end
                return s