An alternative strategy is to:
- Compute the cumulative counts <= each old bin boundary (like a cumulative distribution).
- Interpolate from that to the new bin boundaries, to get a new cumulative distribution.
- Numerically difference the latter to get the desired result.
I don’t know if it would be faster – it seems like each step would involve simple logic – but there would be some temporaries.