Optimize TreeView::treeWalkModel().

This is done by:
- reducing redundanct building of arrays.
- caching values in variables.