Merge: Ropefix
authorJean Privat <jean@pryen.org>
Fri, 30 Jan 2015 02:01:18 +0000 (09:01 +0700)
committerJean Privat <jean@pryen.org>
Fri, 30 Jan 2015 02:01:18 +0000 (09:01 +0700)
A few modifications to ropes, I discovered that the `+` routine used to create too many Concat nodes passed a certain point, which inceased the RAM use of Strings unnecessarily (might help with #1106's example program, on my machine the memory went from 200M+ used to 20M).

While I was at it, I removed a few old-style-inits that were no longer necessary.

Some others however I could not remove, maybe there is a way I can do so, but with the spec of the new constructors I'm not entirely sure how to do so without retaining unnneeded information or complexifying instanciation, that'll have to wait.

Pull-Request: #1127
Reviewed-by: Jean Privat <jean@pryen.org>
Reviewed-by: Alexandre Terrasa <alexandre@moz-code.org>
Reviewed-by: Alexis Laferrière <alexis.laf@xymus.net>

lib/standard/ropes.nit

index 8186ec9..243f98f 100644 (file)
@@ -74,7 +74,7 @@ end
 private class Concat
        super RopeString
 
-       redef var length: Int
+       redef var length: Int is noinit
 
        redef fun substrings do return new RopeSubstrings(self)
 
@@ -98,10 +98,8 @@ private class Concat
        # Right child of the node
        var right: String
 
-       init(l: String, r: String) is old_style_init do
-               left = l
-               right = r
-               length = l.length + r.length
+       init do
+               length = left.length + right.length
        end
 
        redef fun output do
@@ -155,7 +153,7 @@ private class Concat
                else
                        var r = right
                        var rlen = r.length
-                       if rlen + slen > maxlen then return new Concat(left, new Concat(r, s))
+                       if rlen + slen > maxlen then return new Concat(self, s)
                        return new Concat(left, r + s)
                end
        end
@@ -780,17 +778,15 @@ end
 private class RopeChars
        super StringCharView
 
-       var tgt: RopeString
-
-       init(s: RopeString) is old_style_init do tgt = s
+       redef type SELFTYPE: RopeString
 
        redef fun [](i) do
-               return tgt[i]
+               return target[i]
        end
 
-       redef fun iterator_from(i) do return new RopeIter.from(tgt, i)
+       redef fun iterator_from(i) do return new RopeIter.from(target, i)
 
-       redef fun reverse_iterator_from(i) do return new RopeReviter.from(tgt, i)
+       redef fun reverse_iterator_from(i) do return new RopeReviter.from(target, i)
 
 end