unpack-trees: improve performance of next_cache_entry