From e6921025d11b20d8bd18d29242035ae4dbdb8455 Mon Sep 17 00:00:00 2001 From: Iaroslav Postovalov Date: Fri, 2 Apr 2021 16:46:12 +0700 Subject: [PATCH] Remove redundant try-catch expressions --- .../src/commonMain/kotlin/space/kscience/kmath/ast/MST.kt | 2 +- .../src/jsMain/kotlin/space/kscience/kmath/estree/estree.kt | 6 +----- .../src/jvmMain/kotlin/space/kscience/kmath/asm/asm.kt | 6 +----- 3 files changed, 3 insertions(+), 11 deletions(-) diff --git a/kmath-ast/src/commonMain/kotlin/space/kscience/kmath/ast/MST.kt b/kmath-ast/src/commonMain/kotlin/space/kscience/kmath/ast/MST.kt index 4c37b09f4..538db0caa 100644 --- a/kmath-ast/src/commonMain/kotlin/space/kscience/kmath/ast/MST.kt +++ b/kmath-ast/src/commonMain/kotlin/space/kscience/kmath/ast/MST.kt @@ -58,7 +58,7 @@ public fun Algebra.evaluate(node: MST): T = when (node) { is MST.Numeric -> (this as? NumericAlgebra)?.number(node.value) ?: error("Numeric nodes are not supported by $this") - is MST.Symbolic -> bindSymbol(node.value) ?: error("Symbol '${node.value}' is not supported in $this") + is MST.Symbolic -> bindSymbol(node.value) is MST.Unary -> when { this is NumericAlgebra && node.value is MST.Numeric -> unaryOperationFunction(node.operation)(number(node.value.value)) diff --git a/kmath-ast/src/jsMain/kotlin/space/kscience/kmath/estree/estree.kt b/kmath-ast/src/jsMain/kotlin/space/kscience/kmath/estree/estree.kt index 93b2d54c8..796ffce1e 100644 --- a/kmath-ast/src/jsMain/kotlin/space/kscience/kmath/estree/estree.kt +++ b/kmath-ast/src/jsMain/kotlin/space/kscience/kmath/estree/estree.kt @@ -14,11 +14,7 @@ import space.kscience.kmath.operations.NumericAlgebra internal fun MST.compileWith(algebra: Algebra): Expression { fun ESTreeBuilder.visit(node: MST): BaseExpression = when (node) { is Symbolic -> { - val symbol = try { - algebra.bindSymbol(node.value) - } catch (ignored: IllegalStateException) { - null - } + val symbol = algebra.bindSymbolOrNull(node.value) if (symbol != null) constant(symbol) diff --git a/kmath-ast/src/jvmMain/kotlin/space/kscience/kmath/asm/asm.kt b/kmath-ast/src/jvmMain/kotlin/space/kscience/kmath/asm/asm.kt index 5324d74a1..ee2b6fb54 100644 --- a/kmath-ast/src/jvmMain/kotlin/space/kscience/kmath/asm/asm.kt +++ b/kmath-ast/src/jvmMain/kotlin/space/kscience/kmath/asm/asm.kt @@ -22,11 +22,7 @@ import space.kscience.kmath.operations.NumericAlgebra internal fun MST.compileWith(type: Class, algebra: Algebra): Expression { fun AsmBuilder.visit(node: MST): Unit = when (node) { is Symbolic -> { - val symbol = try { - algebra.bindSymbol(node.value) - } catch (ignored: IllegalStateException) { - null - } + val symbol = algebra.bindSymbolOrNull(node.value) if (symbol != null) loadObjectConstant(symbol as Any) -- 2.34.1