about summary refs log tree commit diff
path: root/library/std/src/sys/stdio/unix.rs
diff options
context:
space:
mode:
authorAurelia Molzer <5550310+HeroicKatora@users.noreply.github.com>2025-03-07 14:38:08 +0100
committerAndreas Molzer <andreas.molzer@gmx.de>2025-03-11 15:58:00 +0100
commit436959e3f710d3161093bfa183e3c5deceff7ccf (patch)
tree8682542159381ef3e21cb7f24c5c0527705917d6 /library/std/src/sys/stdio/unix.rs
parent91a0e1604f343730022bc903cbf201d8b0a86a71 (diff)
downloadrust-436959e3f710d3161093bfa183e3c5deceff7ccf.tar.gz
rust-436959e3f710d3161093bfa183e3c5deceff7ccf.zip
Add PeekMut::refresh
This improves the useability of heaps for priority-based work queues. In
certain scenarios, modifications on the most relevant or critical items are
performed until a condition that determines the work items have been
sufficiently addressed. The loop will repeatedly access the most critical
item and put it back in a sorted position when it is complete. Crucially,
due to the ordering invariant we know that all work was performed when the
completed item remains the most critical. Getting this information from the
heap position avoids a (potentially more costly) check on the item state
itself.

A customized `drop` with boolean result would avoid up to two more
comparisons performed in both the last no-op refresh and Drop code but this
occurs once in each execution of the above scenario whereas refresh occurs
any number of times. Also note that the comparison overhead of Drop is only
taken if the element is mutably inspected to determine the end condition,
i.e. not when refresh itself is the break condition.
Diffstat (limited to 'library/std/src/sys/stdio/unix.rs')
0 files changed, 0 insertions, 0 deletions