BUG-1258: fix TreeNode amortization

As it turns out, the TreeNode can be either fully-amortized or
fully-materialized. This means that we can properly capture which nodes
need to be materialized at pretty much zero cost and then pay that cost
once.

Change-Id: I12baf2e07576a3af1ae167edf21f795beef57c69
Signed-off-by: Robert Varga <rovarga@cisco.com>
Merge "BUG-1258: fix TreeNode amortization"