Skip to content

Instantly share code, notes, and snippets.

@pjenvey
Last active October 24, 2018 18:24
Show Gist options
  • Save pjenvey/661be36b66bb04b94a4ec7661c54180c to your computer and use it in GitHub Desktop.
Save pjenvey/661be36b66bb04b94a4ec7661c54180c to your computer and use it in GitHub Desktop.
diff --git a/channelserver/src/server.rs b/channelserver/src/server.rs
index 5de9069..bf2581a 100644
--- a/channelserver/src/server.rs
+++ b/channelserver/src/server.rs
@@ -278,7 +278,8 @@ impl Handler<Connect> for ChannelServer {
);
let chan_id = &msg.channel.to_simple();
// Is this a new channel request?
- if !self.channels.contains_key(&msg.channel) {
+ use std::collections::hash_map::Entry; // XXX:
+ if let Entry::Vacant(entry) = self.channels.entry(msg.channel) {
// Is this the first time we're requesting this channel?
if !&msg.initial_connect {
let mut attrs = HashMap::new();
@@ -300,12 +301,8 @@ impl Handler<Connect> for ChannelServer {
);
return 0;
}
- self.channels.insert(msg.channel, HashMap::new());
+ let group = entry.insert(HashMap::new());
// self.metrics.borrow().incr("conn.new").ok();
- // we've already checked and created this, so calling unwrap
- // should be safe. Creating here hits lifetime exceptions as
- // well.
- let group = self.channels.get_mut(&msg.channel).unwrap();
if group.len() >= self.settings.borrow().max_channel_connections.into() {
info!(
self.log.log,
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment