lib: kill the class ArrayCapable
authorJean Privat <jean@pryen.org>
Tue, 18 Nov 2014 17:10:31 +0000 (12:10 -0500)
committerJean Privat <jean@pryen.org>
Tue, 18 Nov 2014 21:24:44 +0000 (16:24 -0500)
Signed-off-by: Jean Privat <jean@pryen.org>

lib/dummy_array.nit
lib/standard/collection/array.nit
lib/standard/collection/hash_collection.nit
tests/test_gen.nit
tests/test_native_array.nit

index 21da4bd..88e7008 100644 (file)
@@ -12,7 +12,6 @@
 
 class DummyArray
        super Set[Int]
-       super ArrayCapable[Int]
        private var capacity: Int
        redef var length: Int
        private var keys: NativeArray[Int]
@@ -79,8 +78,8 @@ class DummyArray
        init(capacity: Int)
        do
                _capacity = capacity
-               _keys = calloc_array(capacity)
-               _values = calloc_array(capacity)
+               _keys = new NativeArray[Int](capacity)
+               _values = new NativeArray[Int](capacity)
        end
 end
 
index 7d710bd..ca6e9fa 100644 (file)
@@ -251,7 +251,6 @@ end
 #     assert a == b
 class Array[E]
        super AbstractArray[E]
-       super ArrayCapable[E]
 
        redef fun [](index)
        do
@@ -286,7 +285,7 @@ class Array[E]
                var c = _capacity
                if cap <= c then return
                while c <= cap do c = c * 2 + 2
-               var a = calloc_array(c)
+               var a = new NativeArray[E](c)
                if _capacity > 0 then _items.copy_to(a, _length)
                _items = a
                _capacity = c
@@ -317,7 +316,7 @@ class Array[E]
        init with_capacity(cap: Int)
        do
                assert positive: cap >= 0
-               _items = calloc_array(cap)
+               _items = new NativeArray[E](cap)
                _capacity = cap
                _length = 0
        end
@@ -326,7 +325,7 @@ class Array[E]
        init filled_with(value: E, count: Int)
        do
                assert positive: count >= 0
-               _items = calloc_array(count)
+               _items = new NativeArray[E](count)
                _capacity = count
                _length = count
                var i = 0
@@ -769,12 +768,6 @@ end
 
 # Native classes ##############################################################
 
-# Subclasses of this class can create native arrays
-interface ArrayCapable[E]
-       # Get a new array of `size` elements.
-       protected fun calloc_array(size: Int): NativeArray[E] is intern
-end
-
 # Native Nit array
 # Access are unchecked and it has a fixed size
 # Not for public use: may become private.
index 6490024..8e27c80 100644 (file)
@@ -17,7 +17,6 @@ import array
 
 # A HashCollection is an array of HashNode[K] indexed by the K hash value
 private abstract class HashCollection[K: Object, N: HashNode[Object]]
-       super ArrayCapable[nullable N]
 
        private var array: nullable NativeArray[nullable N] = null # Used to store items
        private var capacity: Int = 0 # Size of _array
@@ -163,7 +162,7 @@ private abstract class HashCollection[K: Object, N: HashNode[Object]]
                _last_accessed_key = null
 
                # get a new array
-               var new_array = calloc_array(cap)
+               var new_array = new NativeArray[nullable N](cap)
                _array = new_array
 
                # clean the new array
index 0d15f98..019f202 100644 (file)
@@ -28,7 +28,7 @@ class Toto[E]
 end
 
 class TestNative
-       super ArrayCapable[Int]
+
 
 init
 do
@@ -39,7 +39,7 @@ do
        a[1] = 2
        print(a[0])
        print(a[1])
-       b = calloc_array(5)
+       b = new NativeArray[Int](5)
        b[0]=200
        b[1]=300
        print(b[0])
index aac7a83..467fa78 100644 (file)
 # limitations under the License.
 
 class Toto
-       super ArrayCapable[Int]
+
 
        fun toto
        do
-               var a = calloc_array(3)
+               var a = new NativeArray[Int](3)
                a[0] = 10
                a[1] = 20
                a[2] = 30