Make CircMap:open_ent_count O(1)
In open_ent_count in circmgr.rs, we have:
// TODO: We want to change this from O(n) back to O(1).
// Maybe we should have the CircMap keep track of
// the open-or-opening entries count.
On !273 (merged), @lyuyuan noted:
While working on resolving this, I noticed the
CircMap::get_mut
method.pub(super) fn get_mut(&mut self, id: CircId) -> Option<&mut CircEnt>
I figured to keep track of the open circs counter in all other methods but this one is a bit tricky. I guess one can change an entry from open/opening to destroy-sent (or vice versa) with the mutable reference returned, and the counter will be out of sync.
In order to fix that issue, we'll either need to remove get_mut
and replace its users with specific transition functions, or we'll need to have it return some kind of a smart pointer which, on drop, updates the count.