diff options
author | Paul Phillips <paulp@improving.org> | 2011-07-14 01:27:04 +0000 |
---|---|---|
committer | Paul Phillips <paulp@improving.org> | 2011-07-14 01:27:04 +0000 |
commit | 733669230a470b60c2ecc92c666f0871cecf22ef (patch) | |
tree | 70ee5f0e49e348e317bfd9db5d2230b433dada31 /src/actors | |
parent | 5e49b4181976f20d28625008a775223dbf8e7f6e (diff) | |
download | scala-733669230a470b60c2ecc92c666f0871cecf22ef.tar.gz scala-733669230a470b60c2ecc92c666f0871cecf22ef.tar.bz2 scala-733669230a470b60c2ecc92c666f0871cecf22ef.zip |
Adding some Sets/Maps to perRunCaches, and elim...
Adding some Sets/Maps to perRunCaches, and eliminating ambiguously named
imports.
Did a tour of the compiler adding a few longer-lived mutable structures
to the per-run cache clearing mechanism. Some of these were not a big
threat, but there is (almost) literally no cost to tracking them and the
fewer mutable structures which are created "lone wolf style" the easier
it is to spot the one playing by his own rules.
While I was at it I followed through on long held ambition to eliminate
the importing of highly ambiguous names like "Map" and "HashSet" from
the mutable and immutable packages. I didn't quite manage elimination
but it's pretty close. Something potentially as pernicious which I
didn't do much about is this import:
import scala.collection._
Imagine coming across that one on lines 407 and 474 of a 1271 file.
That's not cool. Some poor future programmer will be on line 1100 and
use "Map[A, B]" in some function and only after the product has shipped
will it be discovered that the signature is wrong and the rocket will
now be crashing into the mountainside straightaway. No review.
Diffstat (limited to 'src/actors')
6 files changed, 17 insertions, 19 deletions
diff --git a/src/actors/scala/actors/remote/NetKernel.scala b/src/actors/scala/actors/remote/NetKernel.scala index c335f5cc59..c6b2d8b8cd 100644 --- a/src/actors/scala/actors/remote/NetKernel.scala +++ b/src/actors/scala/actors/remote/NetKernel.scala @@ -10,7 +10,7 @@ package scala.actors package remote -import scala.collection.mutable.{HashMap, HashSet} +import scala.collection.mutable case class NamedSend(senderLoc: Locator, receiverLoc: Locator, data: Array[Byte], session: Symbol) @@ -39,8 +39,8 @@ private[remote] class NetKernel(service: Service) { sendToNode(receiverLoc.node, NamedSend(senderLoc, receiverLoc, bytes, session)) } - private val actors = new HashMap[Symbol, OutputChannel[Any]] - private val names = new HashMap[OutputChannel[Any], Symbol] + private val actors = new mutable.HashMap[Symbol, OutputChannel[Any]] + private val names = new mutable.HashMap[OutputChannel[Any], Symbol] def register(name: Symbol, a: OutputChannel[Any]): Unit = synchronized { actors += Pair(name, a) @@ -83,7 +83,7 @@ private[remote] class NetKernel(service: Service) { p } - val proxies = new HashMap[(Node, Symbol), Proxy] + val proxies = new mutable.HashMap[(Node, Symbol), Proxy] def getOrCreateProxy(senderNode: Node, senderName: Symbol): Proxy = proxies.synchronized { diff --git a/src/actors/scala/actors/remote/Proxy.scala b/src/actors/scala/actors/remote/Proxy.scala index bf066ae015..02b301b935 100644 --- a/src/actors/scala/actors/remote/Proxy.scala +++ b/src/actors/scala/actors/remote/Proxy.scala @@ -10,7 +10,7 @@ package scala.actors package remote -import scala.collection.mutable.HashMap +import scala.collection.mutable /** * @author Philipp Haller @@ -113,8 +113,8 @@ private[remote] case class Apply0(rfun: Function2[AbstractActor, Proxy, Unit]) * @author Philipp Haller */ private[remote] class DelegateActor(creator: Proxy, node: Node, name: Symbol, kernel: NetKernel) extends Actor { - var channelMap = new HashMap[Symbol, OutputChannel[Any]] - var sessionMap = new HashMap[OutputChannel[Any], Symbol] + var channelMap = new mutable.HashMap[Symbol, OutputChannel[Any]] + var sessionMap = new mutable.HashMap[OutputChannel[Any], Symbol] def act() { Actor.loop { diff --git a/src/actors/scala/actors/remote/TcpService.scala b/src/actors/scala/actors/remote/TcpService.scala index d156443fcb..be34e93cdd 100644 --- a/src/actors/scala/actors/remote/TcpService.scala +++ b/src/actors/scala/actors/remote/TcpService.scala @@ -16,7 +16,7 @@ import java.io.{DataInputStream, DataOutputStream, IOException} import java.lang.{Thread, SecurityException} import java.net.{InetAddress, ServerSocket, Socket, UnknownHostException} -import scala.collection.mutable.HashMap +import scala.collection.mutable import scala.util.Random /* Object TcpService. @@ -26,7 +26,7 @@ import scala.util.Random */ object TcpService { private val random = new Random - private val ports = new HashMap[Int, TcpService] + private val ports = new mutable.HashMap[Int, TcpService] def apply(port: Int, cl: ClassLoader): TcpService = ports.get(port) match { @@ -73,7 +73,7 @@ class TcpService(port: Int, cl: ClassLoader) extends Thread with Service { private val internalNode = new Node(InetAddress.getLocalHost().getHostAddress(), port) def node: Node = internalNode - private val pendingSends = new HashMap[Node, List[Array[Byte]]] + private val pendingSends = new mutable.HashMap[Node, List[Array[Byte]]] /** * Sends a byte array to another node on the network. @@ -161,7 +161,7 @@ class TcpService(port: Int, cl: ClassLoader) extends Thread with Service { // connection management private val connections = - new scala.collection.mutable.HashMap[Node, TcpServiceWorker] + new mutable.HashMap[Node, TcpServiceWorker] private[actors] def addConnection(node: Node, worker: TcpServiceWorker) = synchronized { connections += Pair(node, worker) diff --git a/src/actors/scala/actors/scheduler/ActorGC.scala b/src/actors/scala/actors/scheduler/ActorGC.scala index 473fba1a1c..41ec401dbf 100644 --- a/src/actors/scala/actors/scheduler/ActorGC.scala +++ b/src/actors/scala/actors/scheduler/ActorGC.scala @@ -11,8 +11,7 @@ package scala.actors package scheduler import java.lang.ref.{Reference, WeakReference, ReferenceQueue} - -import scala.collection.mutable.HashSet +import scala.collection.mutable /** * ActorGC keeps track of the number of live actors being managed by a @@ -35,7 +34,7 @@ trait ActorGC extends TerminationMonitor { * this ActorGC. It is maintained so that the WeakReferences will not be GC'd * before the actors to which they point. */ - private val refSet = new HashSet[Reference[t] forSome { type t <: TrackedReactor }] + private val refSet = new mutable.HashSet[Reference[t] forSome { type t <: TrackedReactor }] /** newActor is invoked whenever a new actor is started. */ override def newActor(a: TrackedReactor) = synchronized { diff --git a/src/actors/scala/actors/scheduler/SingleThreadedScheduler.scala b/src/actors/scala/actors/scheduler/SingleThreadedScheduler.scala index 021c70681f..70554ec658 100644 --- a/src/actors/scala/actors/scheduler/SingleThreadedScheduler.scala +++ b/src/actors/scala/actors/scheduler/SingleThreadedScheduler.scala @@ -10,7 +10,7 @@ package scala.actors package scheduler -import scala.collection.mutable.Queue +import scala.collection.mutable /** * This scheduler executes actor tasks on the current thread. @@ -19,7 +19,7 @@ import scala.collection.mutable.Queue */ class SingleThreadedScheduler extends IScheduler { - private val tasks = new Queue[Runnable] + private val tasks = new mutable.Queue[Runnable] /** The maximum number of nested tasks that are run * without unwinding the call stack. diff --git a/src/actors/scala/actors/scheduler/TerminationMonitor.scala b/src/actors/scala/actors/scheduler/TerminationMonitor.scala index e4b9743ab5..032c10af6a 100644 --- a/src/actors/scala/actors/scheduler/TerminationMonitor.scala +++ b/src/actors/scala/actors/scheduler/TerminationMonitor.scala @@ -6,17 +6,16 @@ ** |/ ** \* */ - package scala.actors package scheduler -import scala.collection.mutable.HashMap +import scala.collection.mutable private[scheduler] trait TerminationMonitor { _: IScheduler => protected var activeActors = 0 - protected val terminationHandlers = new HashMap[TrackedReactor, () => Unit] + protected val terminationHandlers = new mutable.HashMap[TrackedReactor, () => Unit] private var started = false /** newActor is invoked whenever a new actor is started. */ |