Skip to content

Commit

Permalink
minor enhance
Browse files Browse the repository at this point in the history
  • Loading branch information
cloud-fan committed Feb 28, 2015
1 parent e0e64ba commit 946a35b
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -71,12 +71,16 @@ class PrimitiveVector[@specialized(Long, Int, Double) V: ClassTag](initialSize:

/** Resizes the array, dropping elements if the total length decreases. */
def resize(newLength: Int): PrimitiveVector[V] = {
val newArray = new Array[V](newLength)
_array.copyToArray(newArray)
_array = newArray
_array = copyArrayWithLength(newLength)
if (newLength < _numElements) {
_numElements = newLength
}
this
}

protected def copyArrayWithLength(length: Int): Array[V] = {
val copy = new Array[V](length)
_array.copyToArray(copy)
copy
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,6 @@ private[spark] class SizeTrackingVector[T: ClassTag]
* Return a trimmed version of the underlying array.
*/
def toArray: Array[T] = {
super.iterator.toArray
super.copyArrayWithLength(size)
}
}

0 comments on commit 946a35b

Please sign in to comment.