@@ -326,48 +326,53 @@ object IArray:
326326 def +: (arr : IArray [U ]): IArray [U ] = genericArrayOps(arr).prepended(x)
327327
328328 /** Conversion from IArray to immutable.ArraySeq */
329- implicit def genericWrapArray [T ](arr : IArray [T ]): scala.collection. immutable.ArraySeq [T ] =
330- scala.collection. immutable.ArraySeq .unsafeWrapArray(arr. asInstanceOf [ Array [ T ]] )
329+ implicit def genericWrapArray [T ](arr : IArray [T ]): immutable.ArraySeq [T ] =
330+ if arr eq null then null else immutable.ArraySeq .unsafeWrapArray(arr)
331331
332332 /** Conversion from IArray to immutable.ArraySeq */
333- implicit def wrapRefArray [T <: AnyRef ](arr : IArray [T ]): scala.collection.immutable.ArraySeq [T ] =
334- scala.collection.immutable.ArraySeq .ofRef(arr.asInstanceOf [Array [T ]])
333+ implicit def wrapRefArray [T <: AnyRef ](arr : IArray [T ]): immutable.ArraySeq .ofRef[T ] =
334+ // Since the JVM thinks arrays are covariant, one 0-length Array[AnyRef]
335+ // is as good as another for all T <: AnyRef. Instead of creating 100,000,000
336+ // unique ones by way of this implicit, let's share one.
337+ if (arr eq null ) null
338+ else if (arr.length == 0 ) immutable.ArraySeq .empty[AnyRef ].asInstanceOf [immutable.ArraySeq .ofRef[T ]]
339+ else immutable.ArraySeq .ofRef(arr.asInstanceOf [Array [T ]])
335340
336341 /** Conversion from IArray to immutable.ArraySeq */
337- implicit def wrapIntArray (arr : IArray [Int ]): scala.collection. immutable.ArraySeq [ Int ] =
338- scala.collection. immutable.ArraySeq .ofInt(arr.asInstanceOf [Array [Int ]])
342+ implicit def wrapIntArray (arr : IArray [Int ]): immutable.ArraySeq .ofInt =
343+ if (arr ne null ) new immutable.ArraySeq .ofInt(arr.asInstanceOf [Array [Int ]]) else null
339344
340345 /** Conversion from IArray to immutable.ArraySeq */
341- implicit def wrapDoubleIArray (arr : IArray [Double ]): collection. immutable.ArraySeq [ Double ] =
342- scala.collection. immutable.ArraySeq .ofDouble(arr.asInstanceOf [Array [Double ]])
346+ implicit def wrapDoubleIArray (arr : IArray [Double ]): immutable.ArraySeq .ofDouble =
347+ if (arr ne null ) new immutable.ArraySeq .ofDouble(arr.asInstanceOf [Array [Double ]]) else null
343348
344349 /** Conversion from IArray to immutable.ArraySeq */
345- implicit def wrapLongIArray (arr : IArray [Long ]): collection. immutable.ArraySeq [ Long ] =
346- scala.collection. immutable.ArraySeq .ofLong(arr.asInstanceOf [Array [Long ]])
350+ implicit def wrapLongIArray (arr : IArray [Long ]): immutable.ArraySeq .ofLong =
351+ if (arr ne null ) new immutable.ArraySeq .ofLong(arr.asInstanceOf [Array [Long ]]) else null
347352
348353 /** Conversion from IArray to immutable.ArraySeq */
349- implicit def wrapFloatIArray (arr : IArray [Float ]): collection. immutable.ArraySeq [ Float ] =
350- scala.collection. immutable.ArraySeq .ofFloat(arr.asInstanceOf [Array [Float ]])
354+ implicit def wrapFloatIArray (arr : IArray [Float ]): immutable.ArraySeq .ofFloat =
355+ if (arr ne null ) new immutable.ArraySeq .ofFloat(arr.asInstanceOf [Array [Float ]]) else null
351356
352357 /** Conversion from IArray to immutable.ArraySeq */
353- implicit def wrapCharIArray (arr : IArray [Char ]): collection. immutable.ArraySeq [ Char ] =
354- scala.collection. immutable.ArraySeq .ofChar(arr.asInstanceOf [Array [Char ]])
358+ implicit def wrapCharIArray (arr : IArray [Char ]): immutable.ArraySeq .ofChar =
359+ if (arr ne null ) new immutable.ArraySeq .ofChar(arr.asInstanceOf [Array [Char ]]) else null
355360
356361 /** Conversion from IArray to immutable.ArraySeq */
357- implicit def wrapByteIArray (arr : IArray [Byte ]): collection. immutable.ArraySeq [ Byte ] =
358- scala.collection. immutable.ArraySeq .ofByte(arr.asInstanceOf [Array [Byte ]])
362+ implicit def wrapByteIArray (arr : IArray [Byte ]): immutable.ArraySeq .ofByte =
363+ if (arr ne null ) new immutable.ArraySeq .ofByte(arr.asInstanceOf [Array [Byte ]]) else null
359364
360365 /** Conversion from IArray to immutable.ArraySeq */
361- implicit def wrapShortIArray (arr : IArray [Short ]): collection. immutable.ArraySeq [ Short ] =
362- scala.collection. immutable.ArraySeq .ofShort(arr.asInstanceOf [Array [Short ]])
366+ implicit def wrapShortIArray (arr : IArray [Short ]): immutable.ArraySeq .ofShort =
367+ if (arr ne null ) new immutable.ArraySeq .ofShort(arr.asInstanceOf [Array [Short ]]) else null
363368
364369 /** Conversion from IArray to immutable.ArraySeq */
365- implicit def wrapBooleanIArray (arr : IArray [Boolean ]): collection. immutable.ArraySeq [ Boolean ] =
366- scala.collection. immutable.ArraySeq .ofBoolean(arr.asInstanceOf [Array [Boolean ]])
370+ implicit def wrapBooleanIArray (arr : IArray [Boolean ]): immutable.ArraySeq .ofBoolean =
371+ if (arr ne null ) new immutable.ArraySeq .ofBoolean(arr.asInstanceOf [Array [Boolean ]]) else null
367372
368373 /** Conversion from IArray to immutable.ArraySeq */
369- implicit def wrapUnitIArray (arr : IArray [Unit ]): collection. immutable.ArraySeq [ Unit ] =
370- scala.collection. immutable.ArraySeq .ofUnit(arr.asInstanceOf [Array [Unit ]])
374+ implicit def wrapUnitIArray (arr : IArray [Unit ]): immutable.ArraySeq .ofUnit =
375+ if (arr ne null ) new immutable.ArraySeq .ofUnit(arr.asInstanceOf [Array [Unit ]]) else null
371376
372377 /** Convert an array into an immutable array without copying, the original array
373378 * must _not_ be mutated after this or the guaranteed immutablity of IArray will
0 commit comments