lib: prepare for new constructors
[nit.git] / lib / standard / ropes.nit
index 9220705..843096f 100644 (file)
@@ -122,7 +122,7 @@ abstract class Rope
        private var leaf_cache: nullable LeafCache = null
 
        # Empty Rope
-       init do from("")
+       init do root = new StringLeaf("".as(FlatString))
 
        # Creates a new Rope with `s` as root
        init from(s: String) do
@@ -309,7 +309,18 @@ class RopeString
                return ret
        end
 
-       redef fun +(o) do return insert_at(o.to_s, length)
+       redef fun +(o) do
+               if self.length == 0 then return o.to_s
+               if o.length == 0 then return self
+               var str = o.to_s
+               if str isa FlatString then
+                       return new RopeString.from_root(new Concat(root, new StringLeaf(str)))
+               else if str isa RopeString then
+                       return new RopeString.from_root(new Concat(root, str.root))
+               else
+                       abort
+               end
+       end
 
        redef fun *(n)
        do