lib/standard/ropes: Added BufferLeaf to constructors.
authorLucas Bajolet <r4pass@hotmail.com>
Mon, 23 Jun 2014 15:23:33 +0000 (11:23 -0400)
committerLucas Bajolet <r4pass@hotmail.com>
Thu, 24 Jul 2014 14:05:03 +0000 (10:05 -0400)
Signed-off-by: Lucas Bajolet <r4pass@hotmail.com>

lib/bufferized_ropes.nit

index 0dac054..0d9353e 100644 (file)
@@ -25,4 +25,24 @@ private class BufferLeaf
 
 end
 
+redef class Rope
+
+       # Empty Rope
+       init do root = new BufferLeaf(new FlatBuffer.with_capacity(buf_len))
+
+end
+
+redef class RopeString
+
+       init from(s: String) do
+               if s.length < buf_len then
+                       var b = new FlatBuffer.with_capacity(buf_len)
+                       b.append(s)
+                       root = new BufferLeaf(b)
+               else
+                       if s isa RopeString then root = s.root else root = new StringLeaf(s.as(FlatString))
+               end
+       end
+
+end