Skip to content

Commit

Permalink
Adjust conversion of AbstractFile's name to TypeName
Browse files Browse the repository at this point in the history
The current optimized version tries to avoid temporary strings.
But it doesn't achieve this for classes based by jrt:// (or any
`NioPath`, as the call to `AbstractFile.fileName` internally
constructs a string each time.

This commit uses `.name` (which is a `lazy val`).
  • Loading branch information
retronym committed May 4, 2021
1 parent 31255c3 commit d0396cd
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 18 deletions.
15 changes: 8 additions & 7 deletions src/compiler/scala/tools/nsc/symtab/SymbolLoaders.scala
Original file line number Diff line number Diff line change
Expand Up @@ -199,15 +199,16 @@ abstract class SymbolLoaders {
}
}
private def nameOf(classRep: ClassRepresentation): TermName = {
while(true) {
val len = classRep.nameChars(nameCharBuffer)
if (len == -1) nameCharBuffer = new Array[Char](nameCharBuffer.length * 2)
else return newTermName(nameCharBuffer, 0, len)
val name = classRep.name
val nameLength = name.length
if (nameLength <= nameCharBuffer.length) {
name.getChars(0, nameLength, nameCharBuffer, 0)
newTermName(nameCharBuffer, 0, nameLength)
} else {
newTermName(name)
}
throw new IllegalStateException()
}
private var nameCharBuffer = new Array[Char](256)

private val nameCharBuffer = new Array[Char](512)

/**
* A lazy type that completes itself by calling parameter doComplete.
Expand Down
11 changes: 0 additions & 11 deletions src/compiler/scala/tools/nsc/util/ClassPath.scala
Original file line number Diff line number Diff line change
Expand Up @@ -204,17 +204,6 @@ object ClassPath {
trait ClassRepresentation {
def fileName: String
def name: String
/** Low level way to extract the entry name without allocation. */
final def nameChars(buffer: Array[Char]): Int = {
val ix = fileName.lastIndexOf('.')
val nameLength = if (ix < 0) fileName.length else ix
if (nameLength > buffer.length)
-1
else {
fileName.getChars(0, fileName.lastIndexOf('.'), buffer, 0)
nameLength
}
}
def binary: Option[AbstractFile]
def source: Option[AbstractFile]
}
Expand Down

0 comments on commit d0396cd

Please sign in to comment.