diff options
author | Martin Odersky <odersky@gmail.com> | 2009-07-13 10:38:37 +0000 |
---|---|---|
committer | Martin Odersky <odersky@gmail.com> | 2009-07-13 10:38:37 +0000 |
commit | 7ff290c43f9c25db803983f88bddff7dd7d84360 (patch) | |
tree | 5fcfac1b0a7361a6c0b40b94c1f6b293eac24ca3 /src/library | |
parent | 67d80e7a75cca991308ea2eee60618c18b02c102 (diff) | |
download | scala-7ff290c43f9c25db803983f88bddff7dd7d84360.tar.gz scala-7ff290c43f9c25db803983f88bddff7dd7d84360.tar.bz2 scala-7ff290c43f9c25db803983f88bddff7dd7d84360.zip |
Trying to make typechecker faster by (1) new su...
Trying to make typechecker faster by (1) new subtyping (2) better
implicit caches. Disallowed '42 as a symbol. Added cache method to
Mutable Maps. Better complietion in interactive.
Diffstat (limited to 'src/library')
-rw-r--r-- | src/library/scala/collection/generic/MutableMapTemplate.scala | 9 |
1 files changed, 9 insertions, 0 deletions
diff --git a/src/library/scala/collection/generic/MutableMapTemplate.scala b/src/library/scala/collection/generic/MutableMapTemplate.scala index 62ae9671c7..334fa937a4 100644 --- a/src/library/scala/collection/generic/MutableMapTemplate.scala +++ b/src/library/scala/collection/generic/MutableMapTemplate.scala @@ -96,6 +96,15 @@ trait MutableMapTemplate[A, B, +This <: MutableMapTemplate[A, B, This] with muta */ override def updated[B1 >: B](key: A, value: B1): mutable.Map[A, B1] = this + ((key, value)) + /** If given key is already in this map, returns associated value + * Otherwise, computes value from given expression `op`, stores with key + * in map and returns that value. + */ + def cached(key: A, op: => B) = get(key) match { + case Some(v) => v + case None => val v = op; update(key, v); v + } + /** Add a new key/value mapping and return the map itself. * * @param kv the key/value mapping to be added |