Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Namespace key in map as Str #342

Merged
merged 1 commit into from
Jun 26, 2024
Merged

Conversation

Totodore
Copy link
Owner

Motivation

Most of the Namespace paths are now Str. It allows to avoid lifetime issue and reduce allocations. To match the use of Str in the codebase we can also switch from a Hashmap<Cow<'static, str>, Namespace> to a Hashmap<Str, Namespace>. Thanks to that there is not only no copying when using 'static str (this was already the case) but also when using owned String. For example with dynamic namespaces or when the user provide owned strings.

Fixes also a minor memory leak where namespaces created from dynamic namespaces were keeping a ref to the namespace path in the connect packet. Thus never freeing the packet.

@Totodore Totodore enabled auto-merge (squash) June 26, 2024 14:45
}

/// Closes all engine.io connections and all clients
#[cfg_attr(feature = "tracing", tracing::instrument(skip(self)))]
pub(crate) async fn close(&self) {
#[cfg(feature = "tracing")]
tracing::debug!("closing all namespaces");
let ns = { std::mem::take(&mut *self.ns.write().unwrap()) };
let ns = { std::mem::take(&mut *self.nsps.write().unwrap()) };

Check warning

Code scanning / clippy

mutable key type Warning

mutable key type
@Totodore Totodore merged commit 8aa3f51 into main Jun 26, 2024
12 of 13 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant