Skip to content

Commit 3a60f32

Browse files
committed
Use mangledString instead of toString
Should we do that? mangledString is much more expensive
1 parent a13bc6b commit 3a60f32

File tree

2 files changed

+18
-18
lines changed

2 files changed

+18
-18
lines changed

compiler/src/dotty/tools/dotc/sbt/ExtractAPI.scala

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -207,7 +207,7 @@ private class ExtractAPICollector(implicit val ctx: Context) extends ThunkHolder
207207

208208
val selfType = apiType(sym.givenSelfType)
209209

210-
val name = ExtractDependencies.classNameAsString(sym)
210+
val name = sym.fullName.stripModuleClassSuffix.mangledString
211211

212212
val tparams = sym.typeParams.map(apiTypeParameter).toArray
213213

@@ -316,7 +316,7 @@ private class ExtractAPICollector(implicit val ctx: Context) extends ThunkHolder
316316
if (aIsClass == bIsClass) {
317317
if (aIsClass) {
318318
if (a.is(Module) == b.is(Module))
319-
a.fullName.toString.compareTo(b.fullName.toString)
319+
a.fullName.mangledString.compareTo(b.fullName.mangledString)
320320
else if (a.is(Module))
321321
-1
322322
else
@@ -340,10 +340,10 @@ private class ExtractAPICollector(implicit val ctx: Context) extends ThunkHolder
340340
} else if (sym.isType) {
341341
apiTypeMember(sym.asType)
342342
} else if (sym.is(Mutable, butNot = Accessor)) {
343-
api.Var.of(sym.name.toString, apiAccess(sym), apiModifiers(sym),
343+
api.Var.of(sym.name.mangledString, apiAccess(sym), apiModifiers(sym),
344344
apiAnnotations(sym).toArray, apiType(sym.info))
345345
} else if (sym.isStable) {
346-
api.Val.of(sym.name.toString, apiAccess(sym), apiModifiers(sym),
346+
api.Val.of(sym.name.mangledString, apiAccess(sym), apiModifiers(sym),
347347
apiAnnotations(sym).toArray, apiType(sym.info))
348348
} else {
349349
apiDef(sym.asTerm)
@@ -370,7 +370,7 @@ private class ExtractAPICollector(implicit val ctx: Context) extends ThunkHolder
370370
} else
371371
(0 until pnames.length).map(Function.const(false))
372372
val params = (pnames, ptypes, defaults).zipped.map((pname, ptype, isDefault) =>
373-
api.MethodParameter.of(pname.toString, apiType(ptype),
373+
api.MethodParameter.of(pname.mangledString, apiType(ptype),
374374
isDefault, api.ParameterModifier.Plain))
375375
api.ParameterList.of(params.toArray, mt.isImplicitMethod) :: paramLists(restpe, params.length)
376376
case _ =>
@@ -380,20 +380,20 @@ private class ExtractAPICollector(implicit val ctx: Context) extends ThunkHolder
380380
val tparams = sym.info match {
381381
case pt: TypeLambda =>
382382
(pt.paramNames, pt.paramInfos).zipped.map((pname, pbounds) =>
383-
apiTypeParameter(pname.toString, 0, pbounds.lo, pbounds.hi))
383+
apiTypeParameter(pname.mangledString, 0, pbounds.lo, pbounds.hi))
384384
case _ =>
385385
Nil
386386
}
387387
val vparamss = paramLists(sym.info)
388388
val retTp = sym.info.finalResultType.widenExpr
389389

390-
api.Def.of(sym.name.toString, apiAccess(sym), apiModifiers(sym),
390+
api.Def.of(sym.name.mangledString, apiAccess(sym), apiModifiers(sym),
391391
apiAnnotations(sym).toArray, tparams.toArray, vparamss.toArray, apiType(retTp))
392392
}
393393

394394
def apiTypeMember(sym: TypeSymbol): api.TypeMember = {
395395
val typeParams = Array[api.TypeParameter]()
396-
val name = sym.name.toString
396+
val name = sym.name.mangledString
397397
val access = apiAccess(sym)
398398
val modifiers = apiModifiers(sym)
399399
val as = apiAnnotations(sym)
@@ -439,7 +439,7 @@ private class ExtractAPICollector(implicit val ctx: Context) extends ThunkHolder
439439
sym.owner.thisType
440440
else
441441
tp.prefix
442-
api.Projection.of(apiType(prefix), sym.name.toString)
442+
api.Projection.of(apiType(prefix), sym.name.mangledString)
443443
case AppliedType(tycon, args) =>
444444
def processArg(arg: Type): api.Type = arg match {
445445
case arg @ TypeBounds(lo, hi) => // Handle wildcard parameters
@@ -463,7 +463,7 @@ private class ExtractAPICollector(implicit val ctx: Context) extends ThunkHolder
463463
val apiRes = apiType(tl.resType)
464464
api.Polymorphic.of(apiRes, apiTparams.toArray)
465465
case rt: RefinedType =>
466-
val name = rt.refinedName.toString
466+
val name = rt.refinedName.mangledString
467467
val parent = apiType(rt.parent)
468468

469469
def typeRefinement(name: String, tp: TypeBounds): api.TypeMember = tp match {
@@ -536,7 +536,7 @@ private class ExtractAPICollector(implicit val ctx: Context) extends ThunkHolder
536536
case tp: ParamRef =>
537537
// TODO: Distinguishing parameters based on their names alone is not enough,
538538
// the binder is also needed (at least for type lambdas).
539-
api.ParameterRef.of(tp.paramName.toString)
539+
api.ParameterRef.of(tp.paramName.mangledString)
540540
case tp: LazyRef =>
541541
apiType(tp.ref)
542542
case tp: TypeVar =>
@@ -557,12 +557,12 @@ private class ExtractAPICollector(implicit val ctx: Context) extends ThunkHolder
557557

558558
def apiThis(sym: Symbol): api.Singleton = {
559559
val pathComponents = sym.ownersIterator.takeWhile(!_.isEffectiveRoot)
560-
.map(s => api.Id.of(s.name.toString))
560+
.map(s => api.Id.of(s.name.mangledString))
561561
api.Singleton.of(api.Path.of(pathComponents.toArray.reverse ++ Array(Constants.thisPath)))
562562
}
563563

564564
def apiTypeParameter(tparam: ParamInfo): api.TypeParameter =
565-
apiTypeParameter(tparam.paramName.toString, tparam.paramVariance,
565+
apiTypeParameter(tparam.paramName.mangledString, tparam.paramVariance,
566566
tparam.paramInfo.bounds.lo, tparam.paramInfo.bounds.hi)
567567

568568
def apiTypeParameter(name: String, variance: Int, lo: Type, hi: Type): api.TypeParameter =
@@ -590,7 +590,7 @@ private class ExtractAPICollector(implicit val ctx: Context) extends ThunkHolder
590590
if (sym.privateWithin eq NoSymbol)
591591
Constants.unqualified
592592
else
593-
api.IdQualifier.of(sym.privateWithin.fullName.toString)
593+
api.IdQualifier.of(sym.privateWithin.fullName.mangledString)
594594
if (sym.is(Protected))
595595
api.Protected.of(qualifier)
596596
else
@@ -617,7 +617,7 @@ private class ExtractAPICollector(implicit val ctx: Context) extends ThunkHolder
617617
// To do this properly we would need a way to hash trees and types in
618618
// dotty itself.
619619
val printTypesCtx = ctx.fresh.setSetting(ctx.settings.XprintTypes, true)
620-
annots += marker(Inliner.bodyToInline(s).show(printTypesCtx).toString)
620+
annots += marker(Inliner.bodyToInline(s).show(printTypesCtx))
621621
}
622622

623623
// In the Scala2 ExtractAPI phase we only extract annotations that extend
@@ -641,6 +641,6 @@ private class ExtractAPICollector(implicit val ctx: Context) extends ThunkHolder
641641
// junit tests are annotated @org.junit.Test).
642642
api.Annotation.of(
643643
apiType(annot.tree.tpe), // Used by sbt to find tests to run
644-
Array(api.AnnotationArgument.of("FULLTREE", annot.tree.show.toString)))
644+
Array(api.AnnotationArgument.of("FULLTREE", annot.tree.show)))
645645
}
646646
}

compiler/src/dotty/tools/dotc/sbt/ExtractDependencies.scala

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -87,9 +87,9 @@ class ExtractDependencies extends Phase {
8787
if (ctx.sbtCallback != null) {
8888
extractDeps.usedNames.foreach{
8989
case (rawClassName, usedNames) =>
90-
val className = rawClassName.toString
90+
val className = rawClassName
9191
usedNames.defaultNames.foreach { rawUsedName =>
92-
val useName = rawUsedName.toString
92+
val useName = rawUsedName.stripModuleClassSuffix.mangledString
9393
val useScopes =
9494
usedNames.scopedNames.get(rawUsedName) match {
9595
case None => EnumSet.of(UseScope.Default)

0 commit comments

Comments
 (0)