swift
f637a6d5 - [rbi] Make Partition's lazy canonicalization const

Commit
28 days ago
[rbi] Make Partition's lazy canonicalization const Canonicalization only relabels regions. It rewrites the region numbers in elementToRegionMap so each label is the smallest element in its region, and it never changes which elements share a region. So it does not change what a partition means; it is a lazy normalization that the read-only queries run before they look anything up. Because canonicalize() was non-const, every query that needs it was non-const too: getRegion, areElementsInSameRegion, range. A caller holding a const partition therefore could not ask which region an element is in. It had to copy the whole partition first, including its element-to-region map, just to be allowed to ask a question that reads nothing but that map. Make canonicalize() const, with the body in a private canonicalizeImpl() that a const_cast reaches, and make those three queries const. The next commit uses this to stop copying a predecessor's exit partition before knowing whether the walk will even fork into it. range() now hands out const_iterator. Nothing mutated through it.
Author
Committer
Parents
Loading