diff options
author | Paul Phillips <paulp@improving.org> | 2011-05-08 07:03:28 +0000 |
---|---|---|
committer | Paul Phillips <paulp@improving.org> | 2011-05-08 07:03:28 +0000 |
commit | 41ac77599ce022087ec595b6da4874b39472019b (patch) | |
tree | f188a9e88bc51481d2a5d8ca42e69c2accbd8aa5 /src/compiler/scala/tools/nsc/io/Path.scala | |
parent | b72a9b1455f8f462192f0a6eb3a7544e7600505a (diff) | |
download | scala-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/compiler/scala/tools/nsc/io/Path.scala')
-rw-r--r-- | src/compiler/scala/tools/nsc/io/Path.scala | 14 |
1 files changed, 11 insertions, 3 deletions
diff --git a/src/compiler/scala/tools/nsc/io/Path.scala b/src/compiler/scala/tools/nsc/io/Path.scala index 3cfab55aaa..beae4b8647 100644 --- a/src/compiler/scala/tools/nsc/io/Path.scala +++ b/src/compiler/scala/tools/nsc/io/Path.scala @@ -159,10 +159,18 @@ class Path private[io] (val jfile: JFile) { if (p isSame this) Nil else p :: p.parents } // 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) + def extension: String = { + var i = name.length - 1 + while (i >= 0 && name.charAt(i) != '.') + i -= 1 + + if (i < 0) "" + else name.substring(i + 1) } + // def extension: String = (name lastIndexOf '.') match { + // case -1 => "" + // case idx => name drop (idx + 1) + // } // compares against extensions in a CASE INSENSITIVE way. def hasExtension(ext: String, exts: String*) = { val xs = (ext +: exts) map (_.toLowerCase) |