Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 25 additions & 3 deletions sjsonnet/src/sjsonnet/Val.scala
Original file line number Diff line number Diff line change
Expand Up @@ -245,9 +245,31 @@ object Val {
def value(i: Int): Val = arr(i).value

def asLazyArray: Array[Eval] = arr.asInstanceOf[Array[Eval]]
def asStrictArray: Array[Val] = arr.map(_.value)
def asStrictArray: Array[Val] = {
val len = arr.length
val result = new Array[Val](len)
var i = 0
while (i < len) {
result(i) = arr(i).value
i += 1
}
result
}

def concat(newPos: Position, rhs: Arr): Arr = Arr(newPos, arr ++ rhs.arr)
/**
* Concatenate two arrays using System.arraycopy to avoid ClassTag resolution and ArrayBuilder
* overhead from Scala's `++` operator.
*/
def concat(newPos: Position, rhs: Arr): Arr = {
val lArr = arr
val rArr = rhs.arr
val lLen = lArr.length
val rLen = rArr.length
val result = new Array[Eval](lLen + rLen)
System.arraycopy(lArr, 0, result, 0, lLen)
System.arraycopy(rArr, 0, result, lLen, rLen)
Arr(newPos, result)
}

def iterator: Iterator[Val] = arr.iterator.map(_.value)
def foreach[U](f: Val => U): Unit = {
Expand Down Expand Up @@ -659,7 +681,7 @@ object Val {
case (lNum: Val.Num, rNum: Val.Num) =>
Val.Num(pos, lNum.asDouble + rNum.asDouble)
case (lArr: Val.Arr, rArr: Val.Arr) =>
Val.Arr(pos, lArr.asLazyArray ++ rArr.asLazyArray)
lArr.concat(pos, rArr)
case (lObj: Val.Obj, rObj: Val.Obj) =>
rObj.addSuper(pos, lObj)
case (_: Val.Null, _) =>
Expand Down