Remove redundant try-catch expressions

This commit is contained in:
Iaroslav Postovalov 2021-04-02 16:46:12 +07:00
parent a91d468b74
commit e6921025d1
No known key found for this signature in database
GPG Key ID: 46E15E4A31B3BCD7
3 changed files with 3 additions and 11 deletions

View File

@ -58,7 +58,7 @@ public fun <T> Algebra<T>.evaluate(node: MST): T = when (node) {
is MST.Numeric -> (this as? NumericAlgebra<T>)?.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))

View File

@ -14,11 +14,7 @@ import space.kscience.kmath.operations.NumericAlgebra
internal fun <T> MST.compileWith(algebra: Algebra<T>): Expression<T> {
fun ESTreeBuilder<T>.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)

View File

@ -22,11 +22,7 @@ import space.kscience.kmath.operations.NumericAlgebra
internal fun <T : Any> MST.compileWith(type: Class<T>, algebra: Algebra<T>): Expression<T> {
fun AsmBuilder<T>.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)