Skip to content

Commit 8b71915

Browse files
committed
Special case for allocating zeros
1 parent 00898c2 commit 8b71915

File tree

2 files changed

+13
-1
lines changed

2 files changed

+13
-1
lines changed

examples/benchmarks/are_we_fast_yet/storage.effekt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ def run(n: Int) = {
3131
def buildTreeDepth(depth: Int) { rand: Random }: Tree = {
3232
count.set(count.get + 1);
3333
if (depth == 1) {
34-
Leaf(array(mod(rand.next, 10) + 1, 0))
34+
Leaf(array::allocateZeros(mod(rand.next, 10) + 1))
3535
} else {
3636
Node(
3737
buildTreeDepth(depth - 1){ rand },

libraries/common/array.effekt

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -173,6 +173,18 @@ extern def set[T](arr: Array[T], index: Int, value: T) at global: Unit =
173173

174174
// Derived operations:
175175

176+
/// Allocates a new array initialized with zero integer values.
177+
def allocateZeros(size: Int): Array[Int] =
178+
unsafeAllocate(size)
179+
180+
/// Allocates a new array initialized with zero double values.
181+
def allocateZeros(size: Int): Array[Double] =
182+
unsafeAllocate(size)
183+
184+
/// Allocates a new array initialized with zero double values.
185+
def allocateNones[T](size: Int): Array[Option[T]] =
186+
unsafeAllocate(size)
187+
176188
/// Builds a new Array of size `size` from a computation `index` which gets an index
177189
/// and returns a value that will be on that position in the resulting array
178190
def build[T](size: Int) { index: Int => T }: Array[T] = {

0 commit comments

Comments
 (0)