This function dynamically allocated a list and returned a pointer to this,
presumably under the assumption that copying this kind of object during return
is expensive. However, Named Return Value Optimization (NRVO) applies to this
function. So the compiler can elide the copy during return, making a value
cheaper than a heap pointer here.
* returns a list of variables with total ordering determined by the constraint
* DAG
*/
-list<Variable*> *Blocks::totalOrder() {
- list<Variable*> *order = new list<Variable*>;
+list<Variable*> Blocks::totalOrder() {
+ list<Variable*> order;
for(int i=0;i<nvs;i++) {
vs[i]->visited=false;
}
for(int i=0;i<nvs;i++) {
if(vs[i]->in.empty()) {
- dfsVisit(vs[i],*order);
+ dfsVisit(vs[i],order);
}
}
return order;
void mergeLeft(Block *r);
void mergeRight(Block *l);
void split(Block *b, Block *&l, Block *&r, Constraint *c);
- std::list<Variable*> *totalOrder();
+ std::list<Variable*> totalOrder();
void cleanup();
double cost();
private:
* another so that constraints internal to the block are satisfied.
*/
void VPSC::satisfy() {
- list<Variable*> *vs=bs.totalOrder();
- for(Variable *v : *vs) {
+ list<Variable*> vs=bs.totalOrder();
+ for(Variable *v : vs) {
if(!v->block->deleted) {
bs.mergeLeft(v->block);
}
throw "Unsatisfied constraint";
}
}
- delete vs;
}
void VPSC::refine() {