OSDN Git Service

optimise count of value (#17)
authoroysheng <33340252+oysheng@users.noreply.github.com>
Mon, 15 Oct 2018 07:51:23 +0000 (15:51 +0800)
committerPaladz <yzhu101@uottawa.ca>
Mon, 15 Oct 2018 07:51:23 +0000 (15:51 +0800)
compiler/compile.go

index 5cefdba..c3d277f 100644 (file)
@@ -403,16 +403,6 @@ func compileStatement(b *builder, stk stack, contract *Contract, env *environ, c
                                st.countVarRefs(counts)
                        }
 
-                       // modify value amount because of using only once
-                       if counts[contract.Value.Amount] > 1 {
-                               counts[contract.Value.Amount] = 1
-                       }
-
-                       // modify value asset because of using only once
-                       if counts[contract.Value.Asset] > 1 {
-                               counts[contract.Value.Asset] = 1
-                       }
-
                        for _, st := range stmt.body.trueBody {
                                if stk, err = compileStatement(b, stk, contract, env, clause, counts, st, sequence); err != nil {
                                        return stk, err
@@ -431,16 +421,6 @@ func compileStatement(b *builder, stk stack, contract *Contract, env *environ, c
                                st.countVarRefs(counts)
                        }
 
-                       // modify value amount because of using only once
-                       if counts[contract.Value.Amount] > 1 {
-                               counts[contract.Value.Amount] = 1
-                       }
-
-                       // modify value asset because of using only once
-                       if counts[contract.Value.Asset] > 1 {
-                               counts[contract.Value.Asset] = 1
-                       }
-
                        stk = condStk
                        b.addJump(stk, "endif_"+strSequence)
                        b.addJumpTarget(stk, "else_"+strSequence)
@@ -562,6 +542,7 @@ func compileStatement(b *builder, stk stack, contract *Contract, env *environ, c
                        case stmt.lockedAmount.String() == contract.Value.Amount:
                                stk = b.addAmount(stk, contract.Value.Amount)
                        case stmt.lockedAmount.String() != contract.Value.Amount && lockCounts[contract.Value.Amount] > 0:
+                               counts[contract.Value.Amount] = lockCounts[contract.Value.Amount]
                                stk = b.addAmount(stk, contract.Value.Amount)
                                stk, err = compileExpr(b, stk, contract, clause, env, counts, stmt.lockedAmount)
                                if err != nil {
@@ -579,6 +560,7 @@ func compileStatement(b *builder, stk stack, contract *Contract, env *environ, c
                        case stmt.lockedAsset.String() == contract.Value.Asset:
                                stk = b.addAsset(stk, contract.Value.Asset)
                        case stmt.lockedAsset.String() != contract.Value.Asset && lockCounts[contract.Value.Asset] > 0:
+                               counts[contract.Value.Asset] = lockCounts[contract.Value.Asset]
                                stk = b.addAsset(stk, contract.Value.Asset)
                                stk, err = compileExpr(b, stk, contract, clause, env, counts, stmt.lockedAsset)
                                if err != nil {