From 7ff290c43f9c25db803983f88bddff7dd7d84360 Mon Sep 17 00:00:00 2001 From: Martin Odersky Date: Mon, 13 Jul 2009 10:38:37 +0000 Subject: 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. --- src/library/scala/collection/generic/MutableMapTemplate.scala | 9 +++++++++ 1 file changed, 9 insertions(+) (limited to 'src/library') 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 -- cgit v1.2.3