Minimize allocations during iteration

Always allocate the upper bound for key and value up front
and reuse it during the iteration.