Skip to content

Commit 574302b

Browse files
committed
Restore "manual" copying in EdgePartition.map(Iterator). Add comment to discourage novices like myself from trying to simplify the code.
1 parent 4117a64 commit 574302b

File tree

1 file changed

+8
-2
lines changed

1 file changed

+8
-2
lines changed

graphx/src/main/scala/org/apache/spark/graphx/impl/EdgePartition.scala

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -92,8 +92,14 @@ class EdgePartition[@specialized(Char, Int, Boolean, Byte, Long, Float, Double)
9292
* @return a new edge partition with the attribute values replaced
9393
*/
9494
def map[ED2: ClassTag](iter: Iterator[ED2]): EdgePartition[ED2] = {
95-
val newData = iter.toArray
96-
assert(newData.size == data.size)
95+
// Faster than iter.toArray, because the expected size is known.
96+
val newData = new Array[ED2](data.size)
97+
var i = 0
98+
while (iter.hasNext) {
99+
newData(i) = iter.next()
100+
i += 1
101+
}
102+
assert(newData.size == i)
97103
new EdgePartition(srcIds, dstIds, newData, index)
98104
}
99105

0 commit comments

Comments
 (0)