File tree Expand file tree Collapse file tree 1 file changed +4
-2
lines changed Expand file tree Collapse file tree 1 file changed +4
-2
lines changed Original file line number Diff line number Diff line change @@ -155,7 +155,7 @@ abstract class Enumeration (initial: Int) extends Serializable {
155
155
* @throws NoSuchElementException if no `Value` with a matching
156
156
* name is in this `Enumeration`
157
157
*/
158
- final def withName (s : String ): Value = values.find(_.toString == s). getOrElse(
158
+ final def withName (s : String ): Value = values.byName. getOrElse(s,
159
159
throw new NoSuchElementException (s " No value found for ' $s' " ))
160
160
161
161
/** Creates a fresh value, part of this enumeration. */
@@ -208,7 +208,7 @@ abstract class Enumeration (initial: Int) extends Serializable {
208
208
val value = m.invoke(this ).asInstanceOf [Value ]
209
209
// verify that outer points to the correct Enumeration: ticket #3616.
210
210
if (value.outerEnum eq thisenum) {
211
- val id = Int .unbox( classOf [ Val ] getMethod " id " invoke value)
211
+ val id : Int = value.id
212
212
nmap += ((id, name))
213
213
}
214
214
}
@@ -321,6 +321,8 @@ abstract class Enumeration (initial: Int) extends Serializable {
321
321
super [SortedSet ].zip[B ](that)
322
322
override def collect [B ](pf : PartialFunction [Value , B ])(implicit @ implicitNotFound(ValueSet .ordMsg) ev : Ordering [B ]): immutable.SortedSet [B ] =
323
323
super [SortedSet ].collect[B ](pf)
324
+
325
+ private [Enumeration ] lazy val byName : Map [String , Value ] = iterator.map( v => v.toString -> v).toMap
324
326
}
325
327
326
328
/** A factory object for value sets */
You can’t perform that action at this time.
0 commit comments