Reduce unnecessary vector alloc/free
authorBrian Demsky <bdemsky@uci.edu>
Sat, 6 Jan 2018 00:09:24 +0000 (16:09 -0800)
committerBrian Demsky <bdemsky@uci.edu>
Sat, 6 Jan 2018 00:09:24 +0000 (16:09 -0800)
src/Backend/satencoder.cc
src/Backend/satencoder.h
src/Backend/satfuncopencoder.cc

index bf8ede4..44e3e63 100644 (file)
 
 SATEncoder::SATEncoder(CSolver *_solver) :
        cnf(createCNF()),
-       solver(_solver) {
+       solver(_solver),
+  vector(allocDefVectorEdge()) {
 }
 
 SATEncoder::~SATEncoder() {
        deleteCNF(cnf);
+       deleteVectorEdge(vector);
 }
 
 void SATEncoder::resetSATEncoder() {
index 0347164..9750048 100644 (file)
@@ -64,7 +64,7 @@ private:
        CNF *cnf;
        CSolver *solver;
        BooleanToEdgeMap booledgeMap;
-
+       VectorEdge *vector;
 };
 
 void allocElementConstraintVariables(ElementEncoding *ee, uint numVars);
index 3f85fec..f4eda52 100644 (file)
@@ -34,7 +34,7 @@ Edge SATEncoder::encodeEnumOperatorPredicateSATEncoder(BooleanPredicate *constra
                Element *elem = constraint->inputs.get(i);
                encodeElementSATEncoder(elem);
        }
-       VectorEdge *clauses = allocDefVectorEdge();     // Setup array of clauses
+       VectorEdge *clauses = vector;
 
        uint indices[numDomains];       //setup indices
        bzero(indices, sizeof(uint) * numDomains);
@@ -75,11 +75,11 @@ Edge SATEncoder::encodeEnumOperatorPredicateSATEncoder(BooleanPredicate *constra
                }
        }
        if (getSizeVectorEdge(clauses) == 0) {
-               deleteVectorEdge(clauses);
+               clearVectorEdge(clauses);
                return E_False;
        }
        Edge cor = constraintOR(cnf, getSizeVectorEdge(clauses), exposeArrayEdge(clauses));
-       deleteVectorEdge(clauses);
+       clearVectorEdge(clauses);
        return generateNegation ? constraintNegate(cor) : cor;
 }