@@ -11,19 +11,19 @@ fun MappingVisitor.copyNames(from: Namespace, to: Set<Namespace>, onlyMissing: B
1111 return DelegateMappingVisitor (this , NameCopyDelegate (from to to, onlyMissing = onlyMissing))
1212}
1313
14- fun MappingVisitor.copyNames (vararg from : Pair <Namespace , Set <Namespace >>, onlyMissing : Boolean = true): MappingVisitor {
15- return DelegateMappingVisitor (this , NameCopyDelegate (* from, onlyMissing = onlyMissing))
14+ fun MappingVisitor.copyNames (from : Pair <Namespace , Set <Namespace >>, onlyMissing : Boolean = true): MappingVisitor {
15+ return DelegateMappingVisitor (this , NameCopyDelegate (from, onlyMissing = onlyMissing))
1616}
1717
18- class NameCopyDelegate (vararg val from : Pair <Namespace , Set <Namespace >>, val onlyMissing : Boolean = true ) : NullDelegator() {
18+ class NameCopyDelegate (val from : Pair <Namespace , Set <Namespace >>, val onlyMissing : Boolean = true ) : NullDelegator() {
1919
2020 companion object {
2121
2222 fun Set<Namespace>.ifOnlyMissing (to : Set <Namespace >, onlyMissing : Boolean ): Set <Namespace > {
2323 return if (onlyMissing) to - this else to
2424 }
2525
26- fun <T > fillAllNames (toFill : Array <out Pair <Namespace , Set <Namespace >>>, names : MutableMap <Namespace , T >, onlyMissing : Boolean = true, fillWith : (T ) -> T = { it }) {
26+ inline fun <T > fillAllNames (toFill : Array <out Pair <Namespace , Set <Namespace >>>, names : MutableMap <Namespace , T >, onlyMissing : Boolean = true, fillWith : (T ) -> T = { it }) {
2727 for ((from, to) in toFill) {
2828 val name = names[from] ? : continue
2929 for (namespace in names.keys.ifOnlyMissing(to, onlyMissing)) {
@@ -32,7 +32,7 @@ class NameCopyDelegate(vararg val from: Pair<Namespace, Set<Namespace>>, val onl
3232 }
3333 }
3434
35- fun <T , U > fillNames (toFill : Pair <Namespace , Set <Namespace >>, names : Map <Namespace , T >, onlyMissing : Boolean = true, fillWith : (T ) -> T = { it }, write : (Map <Namespace , T >) -> U ): U ? {
35+ inline fun <T , U > fillNames (toFill : Pair <Namespace , Set <Namespace >>, names : Map <Namespace , T >, onlyMissing : Boolean = true, fillWith : (T ) -> T = { it }, write : (Map <Namespace , T >) -> U ): U ? {
3636 val (from, to) = toFill
3737 val names = names.toMutableMap()
3838 val name = names[from] ? : return null
@@ -45,53 +45,33 @@ class NameCopyDelegate(vararg val from: Pair<Namespace, Set<Namespace>>, val onl
4545 }
4646
4747 override fun visitClass (delegate : MappingVisitor , names : Map <Namespace , InternalName >): ClassVisitor ? {
48- var visitor: ClassVisitor ? = null
49- for (pair in from) {
50- visitor?.visitEnd()
51- visitor = fillNames(pair, names, onlyMissing) {
52- default.visitClass(delegate, names)
53- }
48+ return fillNames(from, names, onlyMissing) {
49+ default.visitClass(delegate, it)
5450 }
55- return visitor ? : default.visitClass(delegate, names)
5651 }
5752
5853 override fun visitPackage (delegate : MappingVisitor , names : Map <Namespace , PackageName >): PackageVisitor ? {
59- var visitor: PackageVisitor ? = null
60- for (pair in from) {
61- visitor?.visitEnd()
62- visitor = fillNames(pair, names, onlyMissing) {
63- default.visitPackage(delegate, names)
64- }
54+ return fillNames(from, names, onlyMissing) {
55+ default.visitPackage(delegate, it)
6556 }
66- return visitor ? : default.visitPackage(delegate, names)
6757 }
6858
6959 override fun visitField (
7060 delegate : ClassVisitor ,
7161 names : Map <Namespace , Pair <String , FieldDescriptor ?>>
7262 ): FieldVisitor ? {
73- var visitor: FieldVisitor ? = null
74- for (pair in from) {
75- visitor?.visitEnd()
76- visitor = fillNames(pair, names, onlyMissing, { it.first to null }) {
77- default.visitField(delegate, names)
78- }
63+ return fillNames(from, names, onlyMissing, { it.first to null }) {
64+ default.visitField(delegate, it)
7965 }
80- return visitor ? : default.visitField(delegate, names)
8166 }
8267
8368 override fun visitMethod (
8469 delegate : ClassVisitor ,
8570 names : Map <Namespace , Pair <String , MethodDescriptor ?>>
8671 ): MethodVisitor ? {
87- var visitor: MethodVisitor ? = null
88- for (pair in from) {
89- visitor?.visitEnd()
90- visitor = fillNames(pair, names, onlyMissing, { it.first to null }) {
91- default.visitMethod(delegate, names)
92- }
72+ return fillNames(from, names, onlyMissing, { it.first to null }) {
73+ default.visitMethod(delegate, it)
9374 }
94- return visitor ? : default.visitMethod(delegate, names)
9575 }
9676
9777 override fun visitParameter (
@@ -100,14 +80,9 @@ class NameCopyDelegate(vararg val from: Pair<Namespace, Set<Namespace>>, val onl
10080 lvOrd : Int? ,
10181 names : Map <Namespace , String >
10282 ): ParameterVisitor ? {
103- var visitor: ParameterVisitor ? = null
104- for (pair in from) {
105- visitor?.visitEnd()
106- visitor = fillNames(pair, names, onlyMissing) {
107- default.visitParameter(delegate, index, lvOrd, names)
108- }
83+ return fillNames(from, names, onlyMissing) {
84+ default.visitParameter(delegate, index, lvOrd, it)
10985 }
110- return visitor ? : default.visitParameter(delegate, index, lvOrd, names)
11186 }
11287
11388 override fun visitLocalVariable (
@@ -116,14 +91,9 @@ class NameCopyDelegate(vararg val from: Pair<Namespace, Set<Namespace>>, val onl
11691 startOp : Int? ,
11792 names : Map <Namespace , String >
11893 ): LocalVariableVisitor ? {
119- var visitor: LocalVariableVisitor ? = null
120- for (pair in from) {
121- visitor?.visitEnd()
122- visitor = fillNames(pair, names, onlyMissing) {
123- default.visitLocalVariable(delegate, lvOrd, startOp, names)
124- }
94+ return fillNames(from, names, onlyMissing) {
95+ default.visitLocalVariable(delegate, lvOrd, startOp, it)
12596 }
126- return visitor ? : default.visitLocalVariable(delegate, lvOrd, startOp, names)
12797 }
12898
12999}
0 commit comments