Skip to content

Commit 6a1407b

Browse files
committed
Slight Reuse Queue Optimization
1 parent 955ac31 commit 6a1407b

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

Sources/CodeEditTextView/Utils/ViewReuseQueue.swift

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ public class ViewReuseQueue<View: NSView, Key: Hashable> {
3535
} else {
3636
view = queuedViews.popFirst() ?? createView()
3737
view.prepareForReuse()
38+
view.isHidden = false
3839
usedViews[key] = view
3940
}
4041
return view
@@ -48,11 +49,14 @@ public class ViewReuseQueue<View: NSView, Key: Hashable> {
4849
/// - Parameter key: The key for the view to reuse.
4950
public func enqueueView(forKey key: Key) {
5051
guard let view = usedViews[key] else { return }
51-
if queuedViews.count < usedViews.count / 4 {
52+
if queuedViews.count < usedViews.count {
5253
queuedViews.append(view)
54+
view.frame = .zero
55+
view.isHidden = true
56+
} else {
57+
view.removeFromSuperviewWithoutNeedingDisplay()
5358
}
5459
usedViews.removeValue(forKey: key)
55-
view.removeFromSuperviewWithoutNeedingDisplay()
5660
}
5761

5862
/// Enqueues all views not in the given set.

0 commit comments

Comments
 (0)