Skip to content
This repository was archived by the owner on Feb 20, 2019. It is now read-only.

Commit 53d8b99

Browse files
committed
Make runtime pickler and unpickler generation uniform
1 parent 89e4912 commit 53d8b99

File tree

1 file changed

+12
-3
lines changed

1 file changed

+12
-3
lines changed

core/src/main/scala/pickling/Pickler.scala

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -45,9 +45,8 @@ object DPickler {
4545
trait GenPicklers extends CorePicklersUnpicklers {
4646

4747
implicit def genPickler[T](implicit format: PickleFormat): SPickler[T] = macro Compat.PicklerMacros_impl[T]
48-
// TODO: the primitive pickler hack employed here is funny, but I think we should fix this one
49-
// since people probably would also have to deal with the necessity to abstract over pickle formats
50-
def genPickler(classLoader: ClassLoader, clazz: Class[_], tag: FastTypeTag[_])(implicit format: PickleFormat, share: refs.Share): SPickler[_] = {
48+
49+
def genPickler(classLoader: ClassLoader, clazz: Class[_], tag: FastTypeTag[_])(implicit pf: PickleFormat, share: refs.Share): SPickler[_] = {
5150
// println(s"generating runtime pickler for $clazz") // NOTE: needs to be an explicit println, so that we don't occasionally fallback to runtime in static cases
5251
val className = if (clazz == null) "null" else clazz.getName
5352
GlobalRegistry.picklerMap.get(className) match {
@@ -60,6 +59,16 @@ trait GenPicklers extends CorePicklersUnpicklers {
6059
val elemPickler = genPickler(classLoader, elemClass, elemTag)
6160

6261
mkRuntimeTravPickler[Array[AnyRef]](mirror, elemClass, elemTag, tag, elemPickler, null)
62+
} else if (className.endsWith("$")) {
63+
// Return an SPickler[_]
64+
// Note: creating a RuntimePickler has too much overhead in this case
65+
new SPickler[Any] {
66+
val format: PickleFormat = pf
67+
def pickle(picklee: Any, builder: PBuilder): Unit = {
68+
builder.beginEntry(picklee)
69+
builder.endEntry()
70+
}
71+
}
6372
} else {
6473
val runtime = new RuntimePickler(classLoader, clazz)
6574
runtime.mkPickler

0 commit comments

Comments
 (0)