@@ -11,6 +11,7 @@ import scala.internal.Chars.isIdentifierStart
11
11
import collection .immutable
12
12
import config .Config
13
13
import java .util .HashMap
14
+ import Contexts .{Context , ctx }
14
15
15
16
import scala .annotation .internal .sharable
16
17
@@ -638,12 +639,18 @@ object Names {
638
639
def typeName (bs : Array [Byte ], offset : Int , len : Int ): TypeName =
639
640
termName(bs, offset, len).toTypeName
640
641
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
+ */
642
646
def termName (s : String ): SimpleName = termName(s.toCharArray, 0 , s.length)
643
647
644
- /** Create a type name from a string, without encoding operators */
648
+ /** Create a type name from a string */
645
649
def typeName (s : String ): TypeName = typeName(s.toCharArray, 0 , s.length)
646
650
651
+ /** Create a term name from a string slice, using a common buffer.
652
+ * This avoids some allocation relative to `termName(s: String)`
653
+ */
647
654
def termName (s : String , from : Int , len : Int )(using ctx : Contexts .Context ): TermName = {
648
655
val base = ctx.base
649
656
@@ -654,7 +661,10 @@ object Names {
654
661
termName(base.nameCharBuffer, 0 , len)
655
662
}
656
663
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 =
658
668
termName(s, from, len).toTypeName
659
669
660
670
table(0 ) = new SimpleName (- 1 , 0 , null )
0 commit comments