summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorIulian Dragos <jaguarul@gmail.com>2008-02-18 21:59:16 +0000
committerIulian Dragos <jaguarul@gmail.com>2008-02-18 21:59:16 +0000
commitb3c3d1a638061ae8bfb2c03d27c23399cfe73ef0 (patch)
treeba6a6aaacccf76e992e69cbb14c86a489098a81e /src
parent41dc7225084c735f0306e0ebb1a9da0fbd9886ff (diff)
downloadscala-b3c3d1a638061ae8bfb2c03d27c23399cfe73ef0.tar.gz
scala-b3c3d1a638061ae8bfb2c03d27c23399cfe73ef0.tar.bz2
scala-b3c3d1a638061ae8bfb2c03d27c23399cfe73ef0.zip
Changed scala.Symbol to be always interned
Diffstat (limited to 'src')
-rw-r--r--src/compiler/scala/tools/nsc/ast/parser/Parsers.scala3
-rw-r--r--src/compiler/scala/tools/nsc/symtab/IdeSupport.scala4
-rw-r--r--src/library/scala/Symbol.scala34
3 files changed, 24 insertions, 17 deletions
diff --git a/src/compiler/scala/tools/nsc/ast/parser/Parsers.scala b/src/compiler/scala/tools/nsc/ast/parser/Parsers.scala
index cd8c084f03..04334951ec 100644
--- a/src/compiler/scala/tools/nsc/ast/parser/Parsers.scala
+++ b/src/compiler/scala/tools/nsc/ast/parser/Parsers.scala
@@ -615,8 +615,7 @@ trait Parsers extends NewScanners with MarkupParsers {
if (isSymLit) {
atPos(pos) {
var symid = scalaDot(nme.Symbol)
- val symobj = Apply(symid, List(t))
- if (isPattern) symobj else Select(symobj, nme.intern)
+ Apply(symid, List(t))
}
} else {
t
diff --git a/src/compiler/scala/tools/nsc/symtab/IdeSupport.scala b/src/compiler/scala/tools/nsc/symtab/IdeSupport.scala
index 097e57950b..50e72bf82f 100644
--- a/src/compiler/scala/tools/nsc/symtab/IdeSupport.scala
+++ b/src/compiler/scala/tools/nsc/symtab/IdeSupport.scala
@@ -532,7 +532,7 @@ trait IdeSupport extends SymbolTable { // added to global, not analyzers.
case _ : Float => 0 : Float
case _ : Double => 0 : Double
case _ : String => "string"
- case _ : scala.Symbol => 'symbol
+ case _ : scala.Symbol => Symbol("symbol")
case value => value
}))
}
@@ -581,4 +581,4 @@ trait IdeSupport extends SymbolTable { // added to global, not analyzers.
case _ => tree
}).setPos(tree.pos)
-} \ No newline at end of file
+}
diff --git a/src/library/scala/Symbol.scala b/src/library/scala/Symbol.scala
index 2c951a4619..e9f5b08a56 100644
--- a/src/library/scala/Symbol.scala
+++ b/src/library/scala/Symbol.scala
@@ -13,13 +13,12 @@ package scala
import scala.collection.jcl
-private[scala] object internedSymbols extends jcl.WeakHashMap[Symbol, ref.WeakReference[Symbol]]
+private[scala] object internedSymbols extends jcl.WeakHashMap[String, ref.WeakReference[Symbol]]
/** <p>
* This class provides a simple way to get unique objects for
- * equal strings. By default, symbols use string equality for
- * equality testing, but interned symbols can be compared using
- * reference equality for the same effect. Instances of
+ * equal strings. Since symbols are interned, they can be compared using
+ * reference equality. Instances of
* <code>Symbol</code> can be created easily with Scala's built-in
* quote mechanism.
* </p>
@@ -27,13 +26,13 @@ private[scala] object internedSymbols extends jcl.WeakHashMap[Symbol, ref.WeakRe
* For instance, the <a href="http://scala-lang.org/" target="_top">Scala</a>
* term <code>'mysym</code> will invoke the constructor of the
* <code>Symbol</code> class in the following way:
- * <code>new Symbol("mysym").intern</code>.
+ * <code>Symbol("mysym")</code>.
* </p>
*
- * @author Martin Odersky
- * @version 1.7, 08/12/2003
+ * @author Martin Odersky, Iulian Dragos
+ * @version 1.8
*/
-final case class Symbol(name: String) {
+final class Symbol private (val name: String) {
/** Converts this symbol to a string.
*/
@@ -41,6 +40,10 @@ final case class Symbol(name: String) {
"'" + name
}
+}
+
+object Symbol {
+
/** <p>
* Makes this symbol into a unique reference.
* </p>
@@ -49,12 +52,17 @@ final case class Symbol(name: String) {
* then they must be identical (wrt reference equality).
* </p>
*
- * @return the unique reference to this symbol.
+ * @return the unique reference to this string.
*/
- def intern: Symbol = internedSymbols.synchronized {
- internedSymbols.get(this).map(_.get).getOrElse(None) match {
+ def apply(name: String): Symbol = internedSymbols.synchronized {
+ internedSymbols.get(name).map(_.get).getOrElse(None) match {
case Some(sym) => sym
case _ =>
- internedSymbols(this) = new ref.WeakReference(this); this
- } }
+ val sym = new Symbol(name)
+ internedSymbols(name) = new ref.WeakReference(sym)
+ sym
+ }
+ }
+
+ def unapply(other: Symbol): Option[String] = Some(other.name)
}