From cb72048ecae5465cf23ecf0b96b178385bae672f Mon Sep 17 00:00:00 2001 From: Johannes Weiss Date: Thu, 28 Nov 2019 10:33:46 +0000 Subject: [PATCH] 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. --- Sources/NIO/PriorityQueue.swift | 7 ------- 1 file changed, 7 deletions(-) diff --git a/Sources/NIO/PriorityQueue.swift b/Sources/NIO/PriorityQueue.swift index 7c410434f..94a383281 100644 --- a/Sources/NIO/PriorityQueue.swift +++ b/Sources/NIO/PriorityQueue.swift @@ -20,30 +20,23 @@ internal struct PriorityQueue { } 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() }