From 48fe27d8fb0357b29484f91f07caf52b2d857367 Mon Sep 17 00:00:00 2001 From: Paul Phillips Date: Wed, 23 Sep 2009 04:18:17 +0000 Subject: Removed StringVector and all uses thereof. --- src/compiler/scala/tools/nsc/io/AbstractFile.scala | 2 +- src/compiler/scala/tools/nsc/io/Path.scala | 13 +- src/compiler/scala/tools/nsc/io/ZipArchive.scala | 5 +- src/compiler/scala/tools/nsc/symtab/Names.scala | 5 +- .../scala/collection/immutable/StringVector.scala | 220 --------------------- 5 files changed, 10 insertions(+), 235 deletions(-) delete mode 100644 src/library/scala/collection/immutable/StringVector.scala diff --git a/src/compiler/scala/tools/nsc/io/AbstractFile.scala b/src/compiler/scala/tools/nsc/io/AbstractFile.scala index f7d73ed200..51bfb741cb 100644 --- a/src/compiler/scala/tools/nsc/io/AbstractFile.scala +++ b/src/compiler/scala/tools/nsc/io/AbstractFile.scala @@ -20,7 +20,7 @@ import scala.collection.mutable.ArrayBuffer */ object AbstractFile { - def isJarOrZip(f: Path) = cond(f.extension) { case Some("zip" | "jar") => true } + def isJarOrZip(f: Path) = cond(f.extension) { case "zip" | "jar" => true } /** Returns "getFile(new File(path))". */ def getFile(path: String): AbstractFile = getFile(Path(path)) diff --git a/src/compiler/scala/tools/nsc/io/Path.scala b/src/compiler/scala/tools/nsc/io/Path.scala index 40b6a3a4ad..ed750e5b11 100644 --- a/src/compiler/scala/tools/nsc/io/Path.scala +++ b/src/compiler/scala/tools/nsc/io/Path.scala @@ -10,7 +10,6 @@ import java.io.{ BufferedInputStream, BufferedOutputStream, File => JFile } import java.net.{ URI, URL } import collection.{ Sequence, Traversable } -import collection.immutable.{ StringVector => SV } import PartialFunction._ import scala.util.Random.nextASCIIString @@ -104,13 +103,11 @@ class Path private[io] (val jfile: JFile) case None => Nil case Some(p) => p :: p.parents } - // if name ends with an extension (e.g. "foo.jpg") returns the extension ("jpg") - def extension: Option[String] = - condOpt(SV.lastIndexWhere(name, _ == '.')) { - case idx if idx != -1 => SV.drop(name, idx + 1) - } - // Alternative approach: - // (Option fromReturnValue SV.lastIndexWhere(name, _ == '.') map (x => SV.drop(name, x + 1)) + // if name ends with an extension (e.g. "foo.jpg") returns the extension ("jpg"), otherwise "" + def extension: String = (name lastIndexOf '.') match { + case -1 => "" + case idx => name drop (idx + 1) + } // Boolean tests def canRead = jfile.canRead() diff --git a/src/compiler/scala/tools/nsc/io/ZipArchive.scala b/src/compiler/scala/tools/nsc/io/ZipArchive.scala index 9f7e02ab6c..54deec939e 100644 --- a/src/compiler/scala/tools/nsc/io/ZipArchive.scala +++ b/src/compiler/scala/tools/nsc/io/ZipArchive.scala @@ -16,7 +16,6 @@ import PartialFunction._ import scala.collection.Traversable import scala.collection.mutable.{ Map, HashMap } -import scala.collection.immutable.{ StringVector => SV } import scala.collection.JavaConversions.asIterator /** @@ -142,7 +141,7 @@ private[io] trait ZipContainer extends AbstractFile protected def splitPath(path: String): (String, String) = { (path lastIndexOf '/') match { case -1 => ("/", path) - case idx => SV.splitAt(path, idx + 1) + case idx => path splitAt (idx + 1) } } @@ -171,7 +170,7 @@ private[io] trait ZipContainer extends AbstractFile */ protected def getDir(dirs: Map[String, DirEntryInterface], path: String): DirEntryInterface = dirs.getOrElseUpdate(path, { - val (home, name) = splitPath(SV init path) + val (home, name) = splitPath(path init) val parent = getDir(dirs, home) val dir = DirEntryConstructor(parent, name, path) parent.entries(name + path.last) = dir diff --git a/src/compiler/scala/tools/nsc/symtab/Names.scala b/src/compiler/scala/tools/nsc/symtab/Names.scala index 603c0f3673..f6101d61d5 100644 --- a/src/compiler/scala/tools/nsc/symtab/Names.scala +++ b/src/compiler/scala/tools/nsc/symtab/Names.scala @@ -89,9 +89,8 @@ class Names { /** "COMPACTIFY" */ private def toMD5(s: String, edge: Int) = { - import collection.immutable.StringVector._ - val prefix = take(s, edge) - val suffix = takeRight(s, edge) + val prefix = s take edge + val suffix = s takeRight edge val marker = "$$$$" val cs = s.toArray diff --git a/src/library/scala/collection/immutable/StringVector.scala b/src/library/scala/collection/immutable/StringVector.scala deleted file mode 100644 index 2cda4cc8be..0000000000 --- a/src/library/scala/collection/immutable/StringVector.scala +++ /dev/null @@ -1,220 +0,0 @@ -/* __ *\ -** ________ ___ / / ___ Scala API ** -** / __/ __// _ | / / / _ | (c) 2002-2009, LAMP/EPFL ** -** __\ \/ /__/ __ |/ /__/ __ | http://scala-lang.org/ ** -** /____/\___/_/ |_/____/_/ | | ** -** |/ ** -\* */ - -// $Id$ - -package scala.collection.immutable - -import scala.util.matching.Regex -import scala.annotation.experimental - -/** An incomplete implementation of all the methods on Vector, - * written as static methods which take a String as a faux "this" - * argument and which are all entirely String-specific, with the - * attendant improvements in performance, return types, etc. - * I looked for the fastest way to do these operations so there - * is some unattractiveness. - * - * Martin: We should disable this because it is superseded in functionality by - * StringLike/StringOps. We need to clarify whether performance is good enough with the new scheme. - * If not, maybe we need to bring back this object in some form. - * - * @author Paul Phillips - * @version 2.8 - */ - -@experimental -object StringVector -{ - private def noSuch(msg: String) = throw new NoSuchElementException(msg) - - final def foreach[T](s: String, f: Char => T): Unit = { - val len = s.length - var i = 0 - while (i < len) { - f(s charAt i) - i += 1 - } - } - - final def filter(s: String, f: Char => Boolean): String = { - val len = s.length - val chars = new Array[Char](len) - var index, i = 0 - while (i < len) { - val c = s charAt i - if (f(c)) { - chars(index) = c - index += 1 - } - i += 1 - } - if (index == i) s - else new String(chars, 0, index) - } - - final def map(s: String, f: Char => Char): String = { - val len = s.length - val chars = new Array[Char](len) - var i = 0 - while (i < len) { - chars(i) = f(s charAt i) - i += 1 - } - new String(chars, 0, len) - } - - final def flatMap(s: String, f: Char => String): String = { - val sb = new StringBuilder - val len = s.length - var i = 0 - while (i < len) { - sb append f(s charAt i) - i += 1 - } - sb.toString() - } - - final def take(s: String, len: Int): String = - if (len <= 0) "" - else if (len >= s.length) s - else s.substring(0, len) - - final def drop(s: String, len: Int): String = - if (len >= s.length) "" - else if (len <= 0) s - else s.substring(len, s.length) - - final def takeRight(s: String, len: Int): String = - if (len <= 0) "" - else if (len >= s.length) s - else s.substring(s.length - len, s.length) - - final def dropRight(s: String, len: Int): String = - if (len <= 0) s - else if (len >= s.length) "" - else s.substring(0, s.length - len) - - final def splitAt(s: String, index: Int): (String, String) = - if (index <= 0) ("", s) - else if (index >= s.length) (s, "") - else (take(s, index), drop(s, index)) - - final def head(s: String): Char = - if (s == "") noSuch("head of empty list") - else s charAt 0 - - final def tail(s: String): String = - if (s == "") noSuch("tail of empty list") - else drop(s, 1) - - final def last(s: String): Char = - if (s == "") noSuch("empty.last") - else s charAt (s.length - 1) - - final def init(s: String): String = - if (s == "") noSuch("empty.init") - else dropRight(s, 1) - - final def endsWith(s: String, suffix: String) = - takeRight(s, suffix.length) == suffix - - final def startsWith(s: String, prefix: String, offset: Int = 0) = - take(drop(s, offset), prefix.length) == prefix - - final def takeWhile(s: String, f: Char => Boolean) = { - val len = s.length - var i = 0 - while (i < len && f(s charAt i)) i += 1 - - take(s, i) - } - final def dropWhile(s: String, f: Char => Boolean) = { - val len = s.length - var i = 0 - while (i < len && f(s charAt i)) i += 1 - - drop(s, i) - } - final def indexWhere(s: String, p: Char => Boolean, from: Int = 0): Int = { - val len = s.length - var i = from - while (i < len) { - if (p(s charAt i)) - return i - } - -1 - } - final def lastIndexWhere(s: String, p: Char => Boolean): Int = lastIndexWhere(s, p, s.length - 1) - final def lastIndexWhere(s: String, p: Char => Boolean, end: Int): Int = { - var i = end - while (i >= 0) { - if (p(s charAt i)) - return i - i -= 1 - } - -1 - } - - final def reverse(s: String): String = { - val sb = new StringBuilder - var i = s.length - 1 - while (i >= 0) { - sb append (s charAt i) - i -= 1 - } - sb.toString - } - - final def find(s: String, p: Char => Boolean): Option[Char] = { - val len = s.length - var i = 0 - while (i < len) { - val c = s charAt i - if (p(c)) return Some(c) - } - None - } - - final def count(s: String, p: Char => Boolean): Int = { - val len = s.length - var total, i = 0 - while (i < len) - if (p(s charAt i)) - total += 1 - - total - } - final def headOption(s: String): Option[Char] = - if (s.isEmpty) None else Some(s charAt 0) - final def lastOption(s: String): Option[Char] = - if (s.isEmpty) None else Some(last(s)) - - final def slice(s: String, from: Int, to: Int) = - s.substring(from, to) - - final def span(s: String, p: Char => Boolean): (String, String) = { - val len = s.length - var i = 0 - while (p(s charAt i)) i += 1 - - splitAt(s, i) - } - - final def partition(s: String, p: Char => Boolean): (String, String) = { - val len = s.length - val sb1, sb2 = new StringBuilder - var i = 0 - while (i < len) { - val c = s charAt i - if (p(c)) sb1 append c else sb2 append c - i += 1 - } - (sb1.toString, sb2.toString) - } -} -- cgit v1.2.3