contract logic based optimisation in D