Don't allocate a temporary `BTreeMap<T, IntWrap>`.
It's unclear why the previous method didn't work, but this one definitely does.