@@ -187,7 +187,7 @@ sealed class HashMap[A, +B] extends AbstractMap[A, B]
187
187
this .merge0(thatHash, 0 , concatMerger[A , B ])
188
188
case that =>
189
189
var result : HashMap [A , B ] = this
190
- that.asInstanceOf [GenTraversableOnce [(A , B )]] foreach { case kv : (_, _) => result = result + kv }
190
+ that.asInstanceOf [GenTraversableOnce [(A , B )]]. foreach( result += _)
191
191
result
192
192
}
193
193
castToThat(result)
@@ -212,9 +212,9 @@ sealed class HashMap[A, +B] extends AbstractMap[A, B]
212
212
val merger = HashMap .concatMerger[A , B ].invert
213
213
val result : HashMap [A , B ] = that match {
214
214
case thatHash : HashMap [A , B ] =>
215
- this .merge0(thatHash, 0 , HashMap .concatMerger[ A , B ].invert )
215
+ this .merge0(thatHash, 0 , merger )
216
216
217
- case that: HasForeachEntry [A , B ] =>
217
+ case that : HasForeachEntry [A , B ] =>
218
218
object adder extends Function2 [A , B , Unit ] {
219
219
var result : HashMap [A , B ] = HashMap .this
220
220
override def apply (key : A , value : B ): Unit = {
@@ -231,12 +231,15 @@ sealed class HashMap[A, +B] extends AbstractMap[A, B]
231
231
result = result.updated0(key, computeHash(key), 0 , kv._2, kv, merger)
232
232
}
233
233
}
234
- that.asInstanceOf [scala. Traversable [(A ,B )]] foreach adder
234
+ that.asInstanceOf [GenTraversableOnce [(A ,B )]] foreach adder
235
235
adder.result
236
236
}
237
237
castToThat(result)
238
238
}
239
239
}
240
+
241
+ // These methods exist to encapsulate the `.asInstanceOf[That]` in a slightly safer way -- only suitable values can
242
+ // be cast and the type of the `CanBuildFrom` guides type inference.
240
243
private [this ] def castToThat [C , That ](m : HashMap [A , B ])(implicit bf : CanBuildFrom [HashMap [A , B ], C , That ]): That = {
241
244
m.asInstanceOf [That ]
242
245
}
0 commit comments