aboutsummaryrefslogtreecommitdiff
path: root/core/src/main/scala/magnolia.scala
diff options
context:
space:
mode:
authorJon Pretty <jon.pretty@propensive.com>2017-11-04 20:11:53 +0100
committerJon Pretty <jon.pretty@propensive.com>2017-11-04 20:11:53 +0100
commitfdd207e848e24fd6fb449a93e024f0405eab3299 (patch)
treeab4f419791f277d43ec834ff2f12bdcbfb42e67b /core/src/main/scala/magnolia.scala
parent4d957fd5a35f1d7eed8643b22132b65696c80c8a (diff)
downloadmagnolia-fdd207e848e24fd6fb449a93e024f0405eab3299.tar.gz
magnolia-fdd207e848e24fd6fb449a93e024f0405eab3299.tar.bz2
magnolia-fdd207e848e24fd6fb449a93e024f0405eab3299.zip
Start of performance-enhancing refactoring
Diffstat (limited to 'core/src/main/scala/magnolia.scala')
-rw-r--r--core/src/main/scala/magnolia.scala34
1 files changed, 12 insertions, 22 deletions
diff --git a/core/src/main/scala/magnolia.scala b/core/src/main/scala/magnolia.scala
index 4d3d3d3..9d345ac 100644
--- a/core/src/main/scala/magnolia.scala
+++ b/core/src/main/scala/magnolia.scala
@@ -78,11 +78,7 @@ object Magnolia {
val genericTypeName: String = genericType.typeSymbol.name.encodedName.toString.toLowerCase
val assignedName: TermName = TermName(c.freshName(s"${genericTypeName}Typeclass"))
recurse(ChainedImplicit(genericType.toString), genericType, assignedName) {
- val inferredImplicit = c.inferImplicitValue(searchType, false, false)
- q"""{
- def $assignedName: $searchType = $inferredImplicit
- $assignedName
- }"""
+ c.inferImplicitValue(searchType, false, false)
}.get
}.toOption.orElse(directInferImplicit(genericType, typeConstructor))
}
@@ -116,7 +112,7 @@ object Magnolia {
val resultType = appliedType(typeConstructor, genericType)
// FIXME: Handle AnyVals
- if(isCaseObject) {
+ val result = if(isCaseObject) {
val termSym = genericType.typeSymbol.companionSymbol
val obj = termSym.asTerm
val className = obj.name.toString
@@ -128,11 +124,7 @@ object Magnolia {
def isObject = true
})
"""
-
- Some(q"""
- def $assignedName: $resultType = $impl
- $assignedName
- """)
+ Some(impl)
} else if(isCaseClass) {
val caseClassParameters = genericType.decls.collect {
case m: MethodSymbol if m.isCaseAccessor => m.asMethod
@@ -171,7 +163,7 @@ object Magnolia {
q"fn($call).asInstanceOf[${imp._3}]"
} })"""
- val impl = q"""
+ q"""
${c.prefix}.join(new _root_.magnolia.JoinContext[$typeConstructor, $genericType] {
def construct[R](fn: ((Param[${typeConstructor}, $genericType]) => Any)): $genericType = $constructor
def typeName: _root_.java.lang.String = $className
@@ -180,11 +172,6 @@ object Magnolia {
def isObject = false
})
"""
-
- q"""
- def $assignedName: $resultType = $impl
- $assignedName
- """
}
} else if(isSealedTrait) {
val genericSubtypes = classType.get.knownDirectSubclasses.to[List]
@@ -224,16 +211,19 @@ object Magnolia {
}"""
}
- val impl = q"""{
+ q"""{
${c.prefix}.split(_root_.scala.collection.immutable.List[_root_.magnolia.Subclass[$typeConstructor, $genericType]](..$subclasses))
}"""
- q"""
- def $assignedName: $resultType = $impl
- $assignedName
- """
}
} else None
+
+ result.map { r =>
+ q"""{
+ def $assignedName: $resultType = $r
+ $assignedName
+ }"""
+ }
}
val genericType: Type = weakTypeOf[T]