Improve speed of --resize while preserving correctness.

- Create an offsets array to say how to map old offsets to new ones.
  Fast, not much memory, reasonable.
- Improve inner loop.
- Avoid overflow.
To 1.74.