Skip to content

Commit 6ccfdc1

Browse files
committed
Add some explaining comments
1 parent 1fd0844 commit 6ccfdc1

File tree

1 file changed

+13
-3
lines changed

1 file changed

+13
-3
lines changed

compiler/src/dotty/tools/dotc/core/Names.scala

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import scala.internal.Chars.isIdentifierStart
1111
import collection.immutable
1212
import config.Config
1313
import java.util.HashMap
14+
import Contexts.{Context, ctx}
1415

1516
import scala.annotation.internal.sharable
1617

@@ -638,12 +639,18 @@ object Names {
638639
def typeName(bs: Array[Byte], offset: Int, len: Int): TypeName =
639640
termName(bs, offset, len).toTypeName
640641

641-
/** Create a term name from a string, without encoding operators */
642+
/** Create a term name from a string.
643+
* See `termName(s: String, from: Int, len: Int) for a more efficient version
644+
* which however requires a Context for its operation
645+
*/
642646
def termName(s: String): SimpleName = termName(s.toCharArray, 0, s.length)
643647

644-
/** Create a type name from a string, without encoding operators */
648+
/** Create a type name from a string */
645649
def typeName(s: String): TypeName = typeName(s.toCharArray, 0, s.length)
646650

651+
/** Create a term name from a string slice, using a common buffer.
652+
* This avoids some allocation relative to `termName(s: String)`
653+
*/
647654
def termName(s: String, from: Int, len: Int)(using ctx: Contexts.Context): TermName = {
648655
val base = ctx.base
649656

@@ -654,7 +661,10 @@ object Names {
654661
termName(base.nameCharBuffer, 0, len)
655662
}
656663

657-
def typeName(s: String, from: Int, len: Int)(using ctx: Contexts.Context): TypeName =
664+
/** Create a type name from a string slice, using a common buffer.
665+
* This avoids some allocation relative to `typeName(s: String)`
666+
*/
667+
def typeName(s: String, from: Int, len: Int)(using Context): TypeName =
658668
termName(s, from, len).toTypeName
659669

660670
table(0) = new SimpleName(-1, 0, null)

0 commit comments

Comments
 (0)