@@ -18,25 +18,23 @@ package com.twitter.chill
1818
1919import scala .collection .mutable .{WrappedArray , WrappedArrayBuilder }
2020
21- class WrappedArraySerializer [T : ClassManifest ] extends KSerializer [WrappedArray [T ]] {
21+ class WrappedArraySerializer [T ] extends KSerializer [WrappedArray [T ]] {
2222
2323 def write (kser : Kryo , out : Output , obj : WrappedArray [T ]) {
24- out.writeInt(obj.size, true )
25- obj.foreach { t =>
26- val tRef = t.asInstanceOf [AnyRef ]
27- kser.writeClassAndObject(out, tRef)
28- // After each intermediate object, flush
29- out.flush()
30- }
24+ // Write the class-manifest, we don't use writeClass because it
25+ // uses the registration system, and this class might not be registered
26+ kser.writeObject(out, obj.elemManifest.erasure)
27+ kser.writeClassAndObject(out, obj.array)
3128 }
3229
3330 def read (kser : Kryo , in : Input , cls : Class [WrappedArray [T ]]) = {
34- val size = in.readInt(true )
35- val bldr = new WrappedArrayBuilder [T ](classManifest[T ])
36- bldr.sizeHint(size)
37- (0 until size).foreach { idx =>
38- bldr += kser.readClassAndObject(in).asInstanceOf [T ]
39- }
31+ // Write the class-manifest, we don't use writeClass because it
32+ // uses the registration system, and this class might not be registered
33+ val clazz = kser.readObject(in, classOf [Class [T ]])
34+ val array = kser.readClassAndObject(in).asInstanceOf [Array [T ]]
35+ val bldr = new WrappedArrayBuilder [T ](ClassManifest .fromClass[T ](clazz))
36+ bldr.sizeHint(array.size)
37+ bldr ++= array
4038 bldr.result()
4139 }
4240}
0 commit comments