-
Notifications
You must be signed in to change notification settings - Fork 359
Description
Heap currently uses regular array subscripting to access the contents of its storage. Array access is pretty fast, but it includes index validation that is (hopefully) unnecessary in Heap's case. I expect the optimizer is able to get rid of these index validations in some (but not all) cases; but it probably makes sense to not have them in the first place.
Rework the low-level heap implementation to operate on UnsafeMutableBuffer storage instead, turning index checks into debug-mode assertions rather than unconditional preconditions.
To do this, it would make sense to introduce a Heap._UnsafeHandle or _UnsafeHeap struct that consists of an UnsafeMutableBufferPointer value, and move most heap operation to that. We'll need to have closure-based read and update helpers that expose a read-only (or read-write) view of the Array storage. (Similar to how Deque and OrderedSet's hash tables work.)