treebuilder: insert sorted

By inserting in the right position, we can keep the vector sorted,
making entry insertion almost twice as fast.