treebuilder: set the attributes before sorting and inserting

We need to set the attributes before we try to insert it into the
vector, as the comparison function needs to know whether the entry is a
tree or not.