lib: update some modules of standard to new constructors
authorJean Privat <jean@pryen.org>
Sat, 1 Nov 2014 19:31:40 +0000 (15:31 -0400)
committerJean Privat <jean@pryen.org>
Sun, 2 Nov 2014 00:25:35 +0000 (20:25 -0400)
Signed-off-by: Jean Privat <jean@pryen.org>

lib/standard/collection/abstract_collection.nit
lib/standard/collection/array.nit
lib/standard/collection/hash_collection.nit
lib/standard/collection/list.nit
lib/standard/collection/range.nit
lib/standard/file.nit
lib/standard/queue.nit
lib/standard/string.nit
lib/standard/string_search.nit

index 843f8eb..a439ec1 100644 (file)
@@ -194,9 +194,6 @@ class Container[E]
 
        redef fun iterator do return new ContainerIterator[E](self)
 
-       # Create a new instance with a given initial value.
-       init(e: E) do item = e
-
        # The stored item
        var item: E is writable
 end
@@ -208,8 +205,6 @@ private class ContainerIterator[E]
 
        redef fun next do is_ok = false
 
-       init(c: Container[E]) do _container = c
-
        redef var is_ok: Bool = true
 
        private var container: Container[E]
@@ -950,8 +945,6 @@ private class CoupleMapIterator[K: Object, V]
        end
 
        private var iter: Iterator[Couple[K,V]]
-
-       init(i: Iterator[Couple[K,V]]) do _iter = i
 end
 
 # Some tools ###################################################################
@@ -964,11 +957,4 @@ class Couple[F, S]
 
        # The second element of the couple.
        var second: S is writable
-
-       # Create a new instance with a first and a second object.
-       init(f: F, s: S)
-       do
-               first = f
-               second = s
-       end
 end
index 70e0b94..de06850 100644 (file)
@@ -408,12 +408,6 @@ private class ArrayIterator[E]
 
        redef fun next do _index += 1
 
-       init(a: AbstractArrayRead[E])
-       do
-               _array = a
-               _index = 0
-       end
-
        redef var index = 0
 
        private var array: AbstractArrayRead[E]
@@ -426,10 +420,9 @@ private class ArrayReverseIterator[E]
 
        redef fun next do _index -= 1
 
-       init(a: AbstractArrayRead[E])
+       init
        do
-               _array = a
-               _index = a.length - 1
+               _index = _array.length - 1
        end
 end
 
@@ -496,8 +489,6 @@ private class ArraySetIterator[E: Object]
 
        redef fun item: E do return _iter.item
 
-       init(iter: ArrayIterator[E]) do _iter = iter
-
        private var iter: ArrayIterator[E]
 end
 
index 7c90189..6490024 100644 (file)
@@ -197,10 +197,6 @@ private abstract class HashNode[K: Object]
        private var prev_item: nullable N = null
        private var prev_in_bucklet: nullable N = null
        private var next_in_bucklet: nullable N = null
-       init(k: K)
-       do
-               _key = k
-       end
 end
 
 # A map implemented with a hash table.
@@ -346,12 +342,6 @@ private class HashMapNode[K: Object, V]
        super HashNode[K]
        redef type N: HashMapNode[K, V]
        private var value: V
-
-       init(k: K, v: V)
-       do
-               super(k)
-               _value = v
-       end
 end
 
 class HashMapIterator[K: Object, V]
@@ -386,12 +376,12 @@ class HashMapIterator[K: Object, V]
        private var map: HashMap[K, V]
 
        # The current node
-       private var node: nullable HashMapNode[K, V]
+       private var node: nullable HashMapNode[K, V] = null
 
-       init(map: HashMap[K, V])
+       init
        do
                _map = map
-               _node = map._first_item
+               _node = _map._first_item
        end
 end
 
@@ -452,11 +442,6 @@ end
 private class HashSetNode[E: Object]
        super HashNode[E]
        redef type N: HashSetNode[E]
-
-       init(e: E)
-       do
-               _key = e
-       end
 end
 
 private class HashSetIterator[E: Object]
@@ -479,12 +464,11 @@ private class HashSetIterator[E: Object]
        private var set: HashSet[E]
 
        # The position in the internal map storage
-       private var node: nullable HashSetNode[E]
+       private var node: nullable HashSetNode[E] = null
 
-       init(set: HashSet[E])
+       init
        do
-               _set = set
-               _node = set._first_item
+               _node = _set._first_item
        end
 end
 
index f80e176..49fb693 100644 (file)
@@ -289,21 +289,19 @@ class ListIterator[E]
        end
 
        # Build a new iterator for `list`.
-       private init(list: List[E])
+       init
        do
-               _list = list
-               _node = list._head
-               _index = 0
+               _node = _list._head
        end
 
        # The current list
        private var list: List[E]
 
        # The current node of the list
-       private var node: nullable ListNode[E]
+       private var node: nullable ListNode[E] = null
 
        # The index of the current node
-       redef var index
+       redef var index = 0
 
        # Remove the current item
        fun delete
@@ -327,9 +325,9 @@ private class ListReverseIterator[E]
                _index -= 1
        end
 
-       private init(list: List[E])
+       init
        do
-               _list = list
+               var list = _list
                _node = list._tail
                _index = list.length
        end
@@ -338,14 +336,10 @@ end
 # Linked nodes that constitute a linked list.
 private class ListNode[E]
        super Container[E]
-       init(i: E)
-       do 
-               item = i
-       end
 
        # The next node.
-       var next: nullable ListNode[E]
+       var next: nullable ListNode[E] = null
 
        # The previous node.
-       var prev: nullable ListNode[E]
+       var prev: nullable ListNode[E] = null
 end
index 31ffaa2..a79f218 100644 (file)
@@ -77,16 +77,15 @@ private class IteratorRange[E: Discrete]
        # Iterator on ranges.
        super Iterator[E]
        private var range: Range[E]
-       redef var item
+       redef var item is noinit
 
        redef fun is_ok do return _item < _range.after
        
        redef fun next do _item = _item.successor(1)
        
-       init(r: Range[E])
+       init
        do
-               _range = r
-               _item = r.first
+               _item = _range.first
        end
 end
 
index 30e48e3..fb89882 100644 (file)
@@ -94,8 +94,6 @@ class IFStream
                end
        end
 
-       private init do end
-       private init without_file do end
 end
 
 # File output stream
@@ -142,9 +140,6 @@ class OFStream
                self.path = path
                _is_writable = true
        end
-       
-       private init do end
-       private init without_file do end
 end
 
 ###############################################################################
@@ -152,7 +147,7 @@ end
 class Stdin
        super IFStream
 
-       private init do
+       init do
                _file = new NativeFile.native_stdin
                path = "/dev/stdin"
                prepare_buffer(1)
@@ -163,7 +158,7 @@ end
 
 class Stdout
        super OFStream
-       private init do
+       init do
                _file = new NativeFile.native_stdout
                path = "/dev/stdout"
                _is_writable = true
@@ -172,7 +167,7 @@ end
 
 class Stderr
        super OFStream
-       private init do
+       init do
                _file = new NativeFile.native_stderr
                path = "/dev/stderr"
                _is_writable = true
index ceab407..ff2ee0d 100644 (file)
@@ -232,8 +232,6 @@ class MinHeap[E: Object]
                init(default_comparator)
        end
 
-       init(comparator: Comparator) do self.comparator = comparator
-
        redef fun is_empty do return items.is_empty
        redef fun length do return items.length
        redef fun iterator do return items.iterator
index 9e7ef6e..e8e4a4e 100644 (file)
@@ -737,11 +737,6 @@ private abstract class StringCharView
 
        private var target: SELFTYPE
 
-       private init(tgt: SELFTYPE)
-       do
-               target = tgt
-       end
-
        redef fun is_empty do return target.is_empty
 
        redef fun length do return target.length
@@ -913,8 +908,6 @@ private class FlatSubstringsIter
 
        var tgt: nullable FlatText
 
-       init(tgt: FlatText) do self.tgt = tgt
-
        redef fun item do
                assert is_ok
                return tgt.as(not null)
index 5aeac25..fcf14c7 100644 (file)
@@ -139,13 +139,10 @@ class BM_Pattern
                end
        end
 
-       # Compile a new motif
-       init(motif: String)
+       init
        do
-               _motif = motif
                _length = _motif.length
                _gs = new Array[Int].with_capacity(_length)
-               _bc_table = new ArrayMap[Char, Int]
                compute_gs
                compute_bc
        end
@@ -154,7 +151,7 @@ class BM_Pattern
        private var motif: String
 
        # length of the motif
-       private var length: Int
+       private var length: Int is noinit
 
        private fun bc(e: Char): Int
        do
@@ -166,10 +163,10 @@ class BM_Pattern
        end
 
        # good shifts
-       private var gs: Array[Int]
+       private var gs: Array[Int] is noinit
        
        # bad characters
-       private var bc_table: Map[Char, Int]
+       private var bc_table = new ArrayMap[Char, Int]
 
        private fun compute_bc
        do
@@ -255,15 +252,11 @@ class Match
        # The contents of the matching part
        redef fun to_s do return string.substring(from,length)
 
-       # Matches `len` characters of `s` from `f`.
-       init(s: String, f: Int, len: Int)
+       init
        do
-               assert positive_length: len >= 0
-               assert valid_from: f >= 0
-               assert valid_after: f + len <= s.length
-               string = s
-               from = f
-               length = len
+               assert positive_length: length >= 0
+               assert valid_from: from >= 0
+               assert valid_after: from + length <= string.length
        end
 end