summaryrefslogtreecommitdiff
path: root/src/compiler/scala/tools/nsc/symtab/Names.scala
diff options
context:
space:
mode:
authorPaul Phillips <paulp@improving.org>2009-09-05 11:32:10 +0000
committerPaul Phillips <paulp@improving.org>2009-09-05 11:32:10 +0000
commit4d209eab310ee089d23413af76b02590a24575cb (patch)
tree21d2644d5e51a1e25554f21e39c73351d8862f85 /src/compiler/scala/tools/nsc/symtab/Names.scala
parentfd1eba71450b3d60fd02dba22f951a32485629d8 (diff)
downloadscala-4d209eab310ee089d23413af76b02590a24575cb.tar.gz
scala-4d209eab310ee089d23413af76b02590a24575cb.tar.bz2
scala-4d209eab310ee089d23413af76b02590a24575cb.zip
Removed custom UTF8 encoding implementation, de...
Removed custom UTF8 encoding implementation, deprecated all its methods, and ran everything through java's built-in decoder.
Diffstat (limited to 'src/compiler/scala/tools/nsc/symtab/Names.scala')
-rw-r--r--src/compiler/scala/tools/nsc/symtab/Names.scala48
1 files changed, 21 insertions, 27 deletions
diff --git a/src/compiler/scala/tools/nsc/symtab/Names.scala b/src/compiler/scala/tools/nsc/symtab/Names.scala
index 3dcff5da0b..603c0f3673 100644
--- a/src/compiler/scala/tools/nsc/symtab/Names.scala
+++ b/src/compiler/scala/tools/nsc/symtab/Names.scala
@@ -8,7 +8,7 @@ package scala.tools.nsc
package symtab
import scala.util.NameTransformer
-import scala.io.UTF8Codec
+import scala.io.Codec
import java.security.MessageDigest
/** The class <code>Names</code> ...
@@ -87,24 +87,19 @@ class Names {
private lazy val md5 = MessageDigest.getInstance("MD5")
- private def toMD5(s: String, prefixSuffixLen: Int) = {
-// println("COMPACTIFY "+s)
- val cs: Array[Char] = s.toCharArray
- val bytes = new Array[Byte](cs.length * 4)
- val len = UTF8Codec.encode(cs, 0, bytes, 0, cs.length)
- md5.update(bytes, 0, len)
- val hash = md5.digest()
- val sb = new StringBuilder
- sb.appendAll(cs, 0, prefixSuffixLen)
- sb.append("$$$$")
- for (i <- 0 until hash.length) {
- val b = hash(i)
- sb.append(((b >> 4) & 0xF).toHexString)
- sb.append((b & 0xF).toHexString)
- }
- sb.append("$$$$")
- sb.appendAll(cs, len - prefixSuffixLen, prefixSuffixLen)
- sb.toString
+ /** "COMPACTIFY" */
+ private def toMD5(s: String, edge: Int) = {
+ import collection.immutable.StringVector._
+ val prefix = take(s, edge)
+ val suffix = takeRight(s, edge)
+ val marker = "$$$$"
+
+ val cs = s.toArray
+ val bytes = Codec fromUTF8 cs
+ md5 update bytes
+ val md5chars = md5.digest() map (b => (b & 0xFF).toHexString) mkString
+
+ prefix + marker + md5chars + marker + suffix
}
def compactify(s: String): String =
@@ -142,11 +137,8 @@ class Names {
* @param len ...
* @return the created term name
*/
- def newTermName(bs: Array[Byte], offset: Int, len: Int): Name = {
- val cs = new Array[Char](bs.length)
- val nchrs = UTF8Codec.decode(bs, offset, cs, 0, len)
- newTermName(cs, 0, nchrs)
- }
+ def newTermName(bs: Array[Byte], offset: Int, len: Int): Name =
+ newTermName(Codec toUTF8 bs.slice(offset, offset + len) mkString)
/** Create a type name from the characters in <code>cs[offset..offset+len-1]</code>.
*
@@ -173,7 +165,6 @@ class Names {
def newTypeName(bs: Array[Byte], offset: Int, len: Int): Name =
newTermName(bs, offset, len).toTypeName
-
def nameChars: Array[Char] = chrs
implicit def view(s: String): Name = newTermName(s)
@@ -228,8 +219,11 @@ class Names {
* Array must have enough remaining space for all bytes
* (i.e. maximally 3*length bytes).
*/
- final def copyUTF8(bs: Array[Byte], offset: Int): Int =
- UTF8Codec.encode(chrs, index, bs, offset, len)
+ final def copyUTF8(bs: Array[Byte], offset: Int): Int = {
+ val bytes = Codec fromUTF8 chrs.slice(index, index + len)
+ compat.Platform.arraycopy(bytes, 0, bs, offset, bytes.length)
+ offset + bytes.length
+ }
/** return the hash value of this name
*/