@@ -326,48 +326,53 @@ object IArray:
326
326
def +: (arr : IArray [U ]): IArray [U ] = genericArrayOps(arr).prepended(x)
327
327
328
328
/** 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)
331
331
332
332
/** 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 ]])
335
340
336
341
/** 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
339
344
340
345
/** 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
343
348
344
349
/** 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
347
352
348
353
/** 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
351
356
352
357
/** 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
355
360
356
361
/** 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
359
364
360
365
/** 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
363
368
364
369
/** 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
367
372
368
373
/** 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
371
376
372
377
/** Convert an array into an immutable array without copying, the original array
373
378
* must _not_ be mutated after this or the guaranteed immutablity of IArray will
0 commit comments