dwrite: Implement ranges merging.