lib/core: remove ropes intrude import in stream
authorLucas Bajolet <lucas.bajolet@gmail.com>
Fri, 6 Apr 2018 05:57:29 +0000 (01:57 -0400)
committerLucas Bajolet <lucas.bajolet@gmail.com>
Tue, 1 May 2018 18:25:31 +0000 (14:25 -0400)
The intrude import of ropes in lib/core/stream was only due to the
ropification of the read_all_bytes.

As the leaves were too small to have a positive impact with the actual
threshold value being chosen here, we remove the ropification in the
read_all function.

This simplifies code a lot, and keeps out the intrude import of the
ropes module.

We also take advantage of this modification to start using codecs here
to decode the string.

Signed-off-by: Lucas Bajolet <lucas.bajolet@gmail.com>

lib/core/stream.nit

index 99e2ddd..28585ae 100644 (file)
@@ -11,7 +11,6 @@
 # Input and output streams of characters
 module stream
 
-intrude import text::ropes
 import error
 intrude import bytes
 import codecs
@@ -237,29 +236,7 @@ abstract class Reader
                var s = read_all_bytes
                var slen = s.length
                if slen == 0 then return ""
-               var rets = ""
-               var pos = 0
-               var str = s.items.clean_utf8(slen)
-               slen = str.byte_length
-               var sits = str.items
-               var remsp = slen
-               while pos < slen do
-                       # The 129 size was decided more or less arbitrarily
-                       # It will require some more benchmarking to compute
-                       # if this is the best size or not
-                       var chunksz = 129
-                       if chunksz > remsp then
-                               rets += new FlatString.with_infos(sits, remsp, pos)
-                               break
-                       end
-                       var st = sits.find_beginning_of_char_at(pos + chunksz - 1)
-                       var byte_length = st - pos
-                       rets += new FlatString.with_infos(sits, byte_length, pos)
-                       pos = st
-                       remsp -= byte_length
-               end
-               if rets isa Concat then return rets.balance
-               return rets
+               return codec.decode_string(s.items, s.length)
        end
 
        # Read all the stream until the eof.