From 3cd00b9df60343767b81d5116196b441cbb5207a Mon Sep 17 00:00:00 2001 From: Iaroslav Postovalov Date: Sun, 20 Dec 2020 18:55:59 +0700 Subject: [PATCH] Inline internal functions with one usage --- .../kscience/kmath/asm/internal/AsmBuilder.kt | 31 ++++++------------- 1 file changed, 10 insertions(+), 21 deletions(-) diff --git a/kmath-ast/src/jvmMain/kotlin/kscience/kmath/asm/internal/AsmBuilder.kt b/kmath-ast/src/jvmMain/kotlin/kscience/kmath/asm/internal/AsmBuilder.kt index 20e42ed25..882b95bf0 100644 --- a/kmath-ast/src/jvmMain/kotlin/kscience/kmath/asm/internal/AsmBuilder.kt +++ b/kmath-ast/src/jvmMain/kotlin/kscience/kmath/asm/internal/AsmBuilder.kt @@ -204,18 +204,13 @@ internal class AsmBuilder( */ fun loadObjectConstant(value: Any, type: Type = tType): Unit = invokeMethodVisitor.run { val idx = if (value in constants) constants.indexOf(value) else constants.also { it += value }.lastIndex - loadThis() + invokeMethodVisitor.load(0, classType) getfield(classType.internalName, "constants", OBJECT_ARRAY_TYPE.descriptor) iconst(idx) visitInsn(AALOAD) if (type != OBJECT_TYPE) checkcast(type) } - /** - * Loads `this` variable. - */ - private fun loadThis(): Unit = invokeMethodVisitor.load(0, classType) - /** * Either loads a numeric constant [value] from the class's constants field or boxes a primitive * constant from the constant pool. @@ -234,27 +229,21 @@ internal class AsmBuilder( SHORT_TYPE -> invokeMethodVisitor.iconst(value.toInt()) } - box(primitive) + val r = PRIMITIVES_TO_BOXED.getValue(primitive) + + invokeMethodVisitor.invokestatic( + r.internalName, + "valueOf", + getMethodDescriptor(r, primitive), + false, + ) + return } loadObjectConstant(value, boxed) } - /** - * Boxes the current value and pushes it. - */ - private fun box(primitive: Type) { - val r = PRIMITIVES_TO_BOXED.getValue(primitive) - - invokeMethodVisitor.invokestatic( - r.internalName, - "valueOf", - getMethodDescriptor(r, primitive), - false, - ) - } - /** * Loads a variable [name] from arguments [Map] parameter of [Expression.invoke]. */