mirror of
https://github.com/hickory-dns/hickory-dns.git
synced 2026-04-25 11:15:54 +03:00
[PR #3105] [MERGED] Use retain() instead of calling remove() in a loop #3560
Labels
No labels
blocked
breaking-change
bug
bug:critical
bug:tests
cleanup
compliance
compliance
compliance
crate:all
crate:client
crate:native-tls
crate:proto
crate:recursor
crate:resolver
crate:resolver
crate:rustls
crate:server
crate:util
dependencies
docs
duplicate
easy
easy
enhance
enhance
enhance
feature:dns-over-https
feature:dns-over-quic
feature:dns-over-tls
feature:dnsssec
feature:global_lb
feature:mdns
feature:tsig
features:edns
has workaround
ops
perf
platform:WASM
platform:android
platform:fuchsia
platform:linux
platform:macos
platform:windows
pull-request
question
test
tools
tools
trust
unclear
wontfix
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set.
Reference
starred/hickory-dns#3560
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
📋 Pull Request Information
Original PR: https://github.com/hickory-dns/hickory-dns/pull/3105
Author: @divergentdave
Created: 7/9/2025
Status: ✅ Merged
Merged: 7/9/2025
Merged by: @djc
Base:
main← Head:david/retain-optimizations📝 Commits (1)
0c61e26Use retain() instead of calling remove() in a loop📊 Changes
3 files changed (+22 additions, -46 deletions)
View changed files
📝
crates/proto/src/rr/rr_set.rs(+5 -12)📝
crates/server/src/store/in_memory/inner.rs(+4 -20)📝
crates/server/src/store/sqlite/mod.rs(+13 -14)📄 Description
I noticed a pattern in a few places of iterating over a collection, filtering the iterator, collecting the indexes or keys into a vector, and then calling
remove()for each index or key in the vector. This PR replaces this pattern with a call toretain()instead, using the logical inverse of the filter predicate. This should be both more idiomatic and more efficient.Furthermore, note that
RecordSet::remove()removes vector elements by index, in increasing index order. This would not be safe if it ever removed more than one element, because the firstVec::remove()call shifts the tail of the vector left, invalidating the semantics of the rest of the stored indices. In this case I think it was fine, because of the invariant that an RRset cannot contain any duplicate records, but just usingretain()is less fragile.🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.