summaryrefslogtreecommitdiff
path: root/src/library/scala/collection/immutable/StringOps.scala
diff options
context:
space:
mode:
authorPaul Phillips <paulp@improving.org>2011-05-08 07:03:28 +0000
committerPaul Phillips <paulp@improving.org>2011-05-08 07:03:28 +0000
commit41ac77599ce022087ec595b6da4874b39472019b (patch)
treef188a9e88bc51481d2a5d8ca42e69c2accbd8aa5 /src/library/scala/collection/immutable/StringOps.scala
parentb72a9b1455f8f462192f0a6eb3a7544e7600505a (diff)
downloadscala-41ac77599ce022087ec595b6da4874b39472019b.tar.gz
scala-41ac77599ce022087ec595b6da4874b39472019b.tar.bz2
scala-41ac77599ce022087ec595b6da4874b39472019b.zip
Takes 30+% off the startup time for scala/scala...
Takes 30+% off the startup time for scala/scalac with a variety of optimizations pinpointed by tracing method invocations. Frequent guest stars in the parade of slowness were: using Lists and ListBuffers when any amount of random access is needed, using Strings as if one shouldn't have to supply 80 characters of .substring noise to drop a character here and there, imagining that code can be reused in any way shape or form without a savage slowness burn being unleashed upon you and everything you have ever loved, String.format, methods which return tuples, and any method written with appealing scala features which turns out to be called a few orders of magnitude more often than the author probably supposed. This may be only the tip of the iceberg. No review.
Diffstat (limited to 'src/library/scala/collection/immutable/StringOps.scala')
-rw-r--r--src/library/scala/collection/immutable/StringOps.scala10
1 files changed, 10 insertions, 0 deletions
diff --git a/src/library/scala/collection/immutable/StringOps.scala b/src/library/scala/collection/immutable/StringOps.scala
index 63d5984b11..5fc71c7259 100644
--- a/src/library/scala/collection/immutable/StringOps.scala
+++ b/src/library/scala/collection/immutable/StringOps.scala
@@ -36,7 +36,17 @@ final class StringOps(override val repr: String) extends StringLike[String] {
/** Creates a string builder buffer as builder for this class */
override protected[this] def newBuilder = StringBuilder.newBuilder
+ override def apply(index: Int): Char = repr charAt index
+ override def slice(from: Int, until: Int): String = {
+ val start = if (from < 0) 0 else from
+ if (until <= start || start >= repr.length)
+ return ""
+
+ val end = if (until > length) length else until
+ repr.substring(start, end)
+ }
override def toString = repr
+ override def length = repr.length
def seq = this.iterator
}