Skip to content

Commit 7e7ac18

Browse files
authored
Merge pull request scala/scala#7118 from joshlemer/mapbuilder-prototype
Optimize s.c.i.HashMap builder
2 parents 063f44b + 96c4587 commit 7e7ac18

File tree

3 files changed

+394
-44
lines changed

3 files changed

+394
-44
lines changed

library/src/scala/collection/immutable/ChampCommon.scala

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,15 @@ private[immutable] abstract class Node[T <: Node[T]] {
5858
result
5959
}
6060

61+
protected final def removeAnyElement(as: Array[Any], ix: Int): Array[Any] = {
62+
if (ix < 0) throw new ArrayIndexOutOfBoundsException
63+
if (ix > as.length - 1) throw new ArrayIndexOutOfBoundsException
64+
val result = new Array[Any](as.length - 1)
65+
arraycopy(as, 0, result, 0, ix)
66+
arraycopy(as, ix + 1, result, ix, as.length - ix - 1)
67+
result
68+
}
69+
6170
protected final def insertElement(as: Array[Int], ix: Int, elem: Int): Array[Int] = {
6271
if (ix < 0) throw new ArrayIndexOutOfBoundsException
6372
if (ix > as.length) throw new ArrayIndexOutOfBoundsException
@@ -67,6 +76,15 @@ private[immutable] abstract class Node[T <: Node[T]] {
6776
arraycopy(as, ix, result, ix + 1, as.length - ix)
6877
result
6978
}
79+
protected final def insertAnyElement(as: Array[Any], ix: Int, elem: Int): Array[Any] = {
80+
if (ix < 0) throw new ArrayIndexOutOfBoundsException
81+
if (ix > as.length) throw new ArrayIndexOutOfBoundsException
82+
val result = new Array[Any](as.length + 1)
83+
arraycopy(as, 0, result, 0, ix)
84+
result(ix) = elem
85+
arraycopy(as, ix, result, ix + 1, as.length - ix)
86+
result
87+
}
7088
}
7189

7290
/**

0 commit comments

Comments
 (0)