dimanche 31 janvier 2016

Emit If block condition in optimized way

I need to generate complex if conditions in my code using IL instructions.

Like (a && b) || (c && (d || e))

The components are provided as && and || operations on two Operand instances. And each Operand may be an operation itself.

Previously conditional ?: operations were used to evaluate the whole value and then perform the check.

But the emitted code were very unoptimized. The IL from the example above may be decompiled as:

(a ? b : 0) ? 1 : (c ? (d ? 1 : e) : 0)

where 0 is false and 1 is true.

I need to make an optimal implementation without using ? : .

What design or algorithm can you recommend for such purpose? Or are there any existing projects from which I can use the code?

Aucun commentaire:

Enregistrer un commentaire