From 8888366bf6ba9da68a4730185f49bc30637a2889 Mon Sep 17 00:00:00 2001 From: Jean Privat Date: Tue, 18 Nov 2014 12:10:31 -0500 Subject: [PATCH] lib: kill the class ArrayCapable Signed-off-by: Jean Privat --- lib/dummy_array.nit | 5 ++--- lib/standard/collection/array.nit | 13 +++---------- lib/standard/collection/hash_collection.nit | 3 +-- tests/test_gen.nit | 4 ++-- tests/test_native_array.nit | 4 ++-- 5 files changed, 10 insertions(+), 19 deletions(-) diff --git a/lib/dummy_array.nit b/lib/dummy_array.nit index 21da4bd..88e7008 100644 --- a/lib/dummy_array.nit +++ b/lib/dummy_array.nit @@ -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 diff --git a/lib/standard/collection/array.nit b/lib/standard/collection/array.nit index 7d710bd..ca6e9fa 100644 --- a/lib/standard/collection/array.nit +++ b/lib/standard/collection/array.nit @@ -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. diff --git a/lib/standard/collection/hash_collection.nit b/lib/standard/collection/hash_collection.nit index 6490024..8e27c80 100644 --- a/lib/standard/collection/hash_collection.nit +++ b/lib/standard/collection/hash_collection.nit @@ -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 diff --git a/tests/test_gen.nit b/tests/test_gen.nit index 0d15f98..019f202 100644 --- a/tests/test_gen.nit +++ b/tests/test_gen.nit @@ -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]) diff --git a/tests/test_native_array.nit b/tests/test_native_array.nit index aac7a83..467fa78 100644 --- a/tests/test_native_array.nit +++ b/tests/test_native_array.nit @@ -13,11 +13,11 @@ # 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 -- 1.7.9.5