From 34cdca9f2eb60facef679cca9c1d7cb4b2ae10dc Mon Sep 17 00:00:00 2001 From: Martin Odersky Date: Sun, 7 Apr 2013 22:57:30 +0200 Subject: Added filter utility method to Scope… MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit … which is more efficient than toList.filter. --- src/dotty/tools/dotc/core/Scopes.scala | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) (limited to 'src/dotty') diff --git a/src/dotty/tools/dotc/core/Scopes.scala b/src/dotty/tools/dotc/core/Scopes.scala index 85104f30f..6bcfc6f6a 100644 --- a/src/dotty/tools/dotc/core/Scopes.scala +++ b/src/dotty/tools/dotc/core/Scopes.scala @@ -288,11 +288,15 @@ object Scopes { override def foreach[U](p: Symbol => U): Unit = toList foreach p - final def filteredScope(p: Symbol => Boolean)(implicit ctx: Context): MutableScope = { - val unfiltered = toList - val filtered = unfiltered filterConserve p - if (filtered eq unfiltered) this - else newScopeWith(filtered: _*) + override def filter(p: Symbol => Boolean): List[Symbol] = { + var syms: List[Symbol] = Nil + var e = lastEntry + while ((e ne null) && e.owner == this) { + val sym = e.sym + if (p(sym)) syms = sym :: syms + e = e.prev + } + syms } } -- cgit v1.2.3