Skip to content

Commit

Permalink
Remove unnecessary filter in enclosedSubClassTrees etc (#77)
Browse files Browse the repository at this point in the history
* ValueEnumOps to value class and typos etc

* remove unnecessary filter in enclosedSubClassTrees
  • Loading branch information
maowug authored and lloydmeta committed Oct 18, 2016
1 parent b02cda8 commit 8911ac1
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 13 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ Enumeratum has the following niceties:
- [`ValueEnum`s](#valueenum) that map to various primitive values and have compile-time uniqueness constraints.
- Idiomatic: you're very clearly still writing Scala, and no funny colours in your IDE means less cognitive overhead for your team
- Simplicity; most of the complexity in this lib is in its macro, and the macro is fairly simple conceptually
- No usage of reflection at run time. This may also help with performance but it means Enumeratum is compatible with ScalaJS and other
- No usage of reflection at runtime. This may also help with performance but it means Enumeratum is compatible with ScalaJS and other
environments where reflection is a best effort (such as Android)
- No usage of `synchronized`, which may help with performance and deadlocks prevention
- All magic happens at compile-time so you know right away when things go awry
Expand Down Expand Up @@ -830,4 +830,4 @@ is acceptable for almost all use-cases. PRs that promise to increase performance

Also, Enumeratum's `withName` is faster than the standard library's `Enumeration`, by around 4x in the case where an entry exists with the given name.
My guess is this is because Enumeratum doesn't use any `synchronized` calls or `volatile` annotations. It is also faster in the case where there is no
corresponding name, but not by a significant amount, perhaps because the high cost of throwing an exception masks any benefits.
corresponding name, but not by a significant amount, perhaps because the high cost of throwing an exception masks any benefits.
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ trait LongEnum[A <: LongEnumEntry] extends ValueEnum[Long, A] {
object ShortEnum {

/**
* Materializes a ShortEnum for an inscope ShortEnumEntry
* Materializes a ShortEnum for an in-scope ShortEnumEntry
*/
implicit def materialiseShortValueEnum[EntryType <: ShortEnumEntry]: ShortEnum[EntryType] =
macro EnumMacros.materializeEnumImpl[EntryType]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ sealed trait ValueEnumEntry[ValueType] {

object ValueEnumEntry {

implicit class ValueEnumOps[A <: ValueEnumEntry[_]](val enumEntry: A) {
implicit class ValueEnumOps[A <: ValueEnumEntry[_]](val enumEntry: A) extends AnyVal {

/**
* Checks if the current enum value is contained by the set of enum values in the parameter list.
Expand Down
13 changes: 4 additions & 9 deletions macros/src/main/scala/enumeratum/EnumMacros.scala
Original file line number Diff line number Diff line change
Expand Up @@ -70,11 +70,8 @@ object EnumMacros {
}
enclosingModule.impl.body.filter { x =>
try {
Option(x.symbol) match {
case Some(sym) if sym.isModule =>
sym.asModule.moduleClass.asClass.baseClasses.contains(typeSymbol)
case _ => false
}
x.symbol.isModule &&
x.symbol.asModule.moduleClass.asClass.baseClasses.contains(typeSymbol)
} catch {
case NonFatal(e) =>
c.warning(
Expand All @@ -87,9 +84,7 @@ object EnumMacros {
case NonFatal(e) =>
c.abort(c.enclosingPosition, s"Unexpected error: ${e.getMessage}")
}
if (!enclosingBodySubClassTrees.forall(x => x.symbol.isModule))
c.abort(c.enclosingPosition, "All subclasses must be objects.")
else enclosingBodySubClassTrees
enclosingBodySubClassTrees
}

/**
Expand All @@ -106,7 +101,7 @@ object EnumMacros {
private[enumeratum] def buildSeqExpr[A: c.WeakTypeTag](c: Context)(
subclassSymbols: Seq[c.universe.Symbol]) = {
import c.universe._
val resultType = implicitly[c.WeakTypeTag[A]].tpe
val resultType = weakTypeOf[A]
if (subclassSymbols.isEmpty) {
c.Expr[IndexedSeq[A]](reify(IndexedSeq.empty[A]).tree)
} else {
Expand Down

0 comments on commit 8911ac1

Please sign in to comment.