mirror of
https://github.com/apple/swift-nio
synced 2026-11-26 04:57:49 +00:00
don't constantly check the heap property in debug mode (#1272)
Motivation: So far we've been checking the heap property of our heaps _twice per heap operation_. I think that's a bit much. Modifications: Remove the heap operation checks. Result: Runs much faster in debug mode.
This commit is contained in:
1 parent
3c879ebbaf
commit
cb72048eca
1 file changed
-7
@@ -20,30 +20,23 @@ internal struct PriorityQueue<Element: Comparable> {
|
||||
}
|
||||
|
||||
public mutating func remove(_ key: Element) {
|
||||
assert(self.heap.checkHeapProperty(), "broken heap: \(self.heap.debugDescription)")
|
||||
self.heap.remove(value: key)
|
||||
assert(self.heap.checkHeapProperty(), "broken heap: \(self.heap.debugDescription)")
|
||||
}
|
||||
|
||||
public mutating func push(_ key: Element) {
|
||||
assert(self.heap.checkHeapProperty(), "broken heap: \(self.heap.debugDescription)")
|
||||
self.heap.append(key)
|
||||
assert(self.heap.checkHeapProperty(), "broken heap: \(self.heap.debugDescription)")
|
||||
}
|
||||
|
||||
public func peek() -> Element? {
|
||||
assert(self.heap.checkHeapProperty(), "broken heap: \(self.heap.debugDescription)")
|
||||
return self.heap.storage.first
|
||||
}
|
||||
|
||||
public var isEmpty: Bool {
|
||||
assert(self.heap.checkHeapProperty(), "broken heap: \(self.heap.debugDescription)")
|
||||
return self.heap.storage.isEmpty
|
||||
}
|
||||
|
||||
@discardableResult
|
||||
public mutating func pop() -> Element? {
|
||||
assert(self.heap.checkHeapProperty(), "broken heap: \(self.heap.debugDescription)")
|
||||
return self.heap.removeRoot()
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user