Skip to content

Commit 402f569

Browse files
committed
Merge pull request #115 from ryanlecompte/develop
fix for #114: issue with specialized types in WrappedArray instances
2 parents 636b1b4 + 48c46d6 commit 402f569

2 files changed

Lines changed: 14 additions & 14 deletions

File tree

chill-scala/src/main/scala/com/twitter/chill/WrappedArraySerializer.scala

Lines changed: 6 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -24,25 +24,17 @@ class WrappedArraySerializer[T] extends KSerializer[WrappedArray[T]] {
2424
// Write the class-manifest, we don't use writeClass because it
2525
// uses the registration system, and this class might not be registered
2626
kser.writeObject(out, obj.elemManifest.erasure)
27-
out.writeInt(obj.size, true)
28-
obj.foreach { t =>
29-
val tRef = t.asInstanceOf[AnyRef]
30-
kser.writeObject(out, tRef)
31-
// After each intermediate object, flush
32-
out.flush
33-
}
27+
kser.writeClassAndObject(out, obj.array)
3428
}
3529

3630
def read(kser: Kryo, in: Input, cls: Class[WrappedArray[T]]) = {
3731
// Write the class-manifest, we don't use writeClass because it
3832
// uses the registration system, and this class might not be registered
39-
val clazz = kser.readObject(in, classOf[Class[T]]).asInstanceOf[Class[T]]
40-
val size = in.readInt(true)
33+
val clazz = kser.readObject(in, classOf[Class[T]])
34+
val array = kser.readClassAndObject(in).asInstanceOf[Array[T]]
4135
val bldr = new WrappedArrayBuilder[T](ClassManifest.fromClass[T](clazz))
42-
bldr.sizeHint(size)
43-
(0 until size).foreach { idx =>
44-
bldr += kser.readObject(in, clazz)
45-
}
46-
bldr.result
36+
bldr.sizeHint(array.size)
37+
bldr ++= array
38+
bldr.result()
4739
}
4840
}

chill-scala/src/test/scala/com/twitter/chill/KryoSpec.scala

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,8 +97,16 @@ class KryoSpec extends Specification with BaseProperties {
9797
arrayRT(Array(0.1))
9898
arrayRT(Array("hey"))
9999
arrayRT(Array((0,1)))
100+
arrayRT(Array((0,1), (1,0)))
100101
arrayRT(Array(None, Nil, None, Nil))
101102
}
103+
"handle WrappedArray instances" in {
104+
val tests = Seq(
105+
Array((1,1), (2,2), (3,3)).toSeq,
106+
Array((1.0, 1.0), (2.0, 2.0)).toSeq,
107+
Array((1.0, "1.0"), (2.0, "2.0")).toSeq)
108+
tests.foreach { test => rt(test) must be_==(test) }
109+
}
102110
"handle lists of lists" in {
103111
val lol = List(("us", List(1)), ("jp", List(3, 2)), ("gb", List(3, 1)))
104112
rt(lol) must be_==(lol)

0 commit comments

Comments
 (0)