aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlex Auvolat <alex@adnab.me>2021-10-18 11:51:37 +0200
committerAlex Auvolat <alex@adnab.me>2021-10-18 11:51:37 +0200
commit448709c1db0659d3adaa6f0b661e88c1d5485d83 (patch)
tree5675783ccce02baa7e045f9578516a3750d41a96
parent040231d554b74e981644e606c096ced6fc36a2ad (diff)
downloadnetapp-448709c1db0659d3adaa6f0b661e88c1d5485d83.tar.gz
netapp-448709c1db0659d3adaa6f0b661e88c1d5485d83.zip
Make a true v0.2.0 releasev0.2.00.2
-rw-r--r--Cargo.lock3
-rw-r--r--Cargo.toml2
-rw-r--r--src/lib.rs2
-rw-r--r--src/proto.rs24
4 files changed, 16 insertions, 15 deletions
diff --git a/Cargo.lock b/Cargo.lock
index 4045aaf..974f327 100644
--- a/Cargo.lock
+++ b/Cargo.lock
@@ -311,7 +311,8 @@ checksum = "9a3a5bfb195931eeb336b2a7b4d761daec841b97f947d34394601737a7bba5e4"
[[package]]
name = "kuska-handshake"
version = "0.2.0"
-source = "git+https://github.com/Alexis211/handshake?branch=tokio1.0#a99e5a9c8591c41c99ce0bdfe18d596e3933bc4e"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "e33da4b69f23c2ece0b3e729d079cebdc2c0206e493e42f510f500ad81c631d5"
dependencies = [
"futures",
"hex",
diff --git a/Cargo.toml b/Cargo.toml
index 5f64a33..956c548 100644
--- a/Cargo.toml
+++ b/Cargo.toml
@@ -39,7 +39,7 @@ bytes = "0.6.0"
lru = { version = "0.6", optional = true }
sodiumoxide = { version = "0.2.5-0", package = "kuska-sodiumoxide" }
-kuska-handshake = { version = "0.2.0", git = "https://github.com/Alexis211/handshake", branch = "tokio1.0", features = ["default", "async_std"] }
+kuska-handshake = { version = "0.2.0", features = ["default", "async_std"] }
[dev-dependencies]
structopt = { version = "0.3", default-features = false }
diff --git a/src/lib.rs b/src/lib.rs
index a0bec32..ca35d85 100644
--- a/src/lib.rs
+++ b/src/lib.rs
@@ -13,8 +13,6 @@
//! about message priorization.
//! Also check out the examples to learn how to use this crate.
-#![feature(map_first_last)]
-
pub mod error;
pub mod util;
diff --git a/src/proto.rs b/src/proto.rs
index ef3b31c..17db5ab 100644
--- a/src/proto.rs
+++ b/src/proto.rs
@@ -1,4 +1,4 @@
-use std::collections::{BTreeMap, HashMap, VecDeque};
+use std::collections::{HashMap, VecDeque};
use std::sync::Arc;
use log::trace;
@@ -50,31 +50,33 @@ struct SendQueueItem {
}
struct SendQueue {
- items: BTreeMap<u8, VecDeque<SendQueueItem>>,
+ items: VecDeque<(u8, VecDeque<SendQueueItem>)>,
}
impl SendQueue {
fn new() -> Self {
Self {
- items: BTreeMap::new(),
+ items: VecDeque::with_capacity(64),
}
}
fn push(&mut self, item: SendQueueItem) {
let prio = item.prio;
- let mut items_at_prio = self
- .items
- .remove(&prio)
- .unwrap_or_else(|| VecDeque::with_capacity(4));
- items_at_prio.push_back(item);
- self.items.insert(prio, items_at_prio);
+ let pos_prio = match self.items.binary_search_by(|(p, _)| p.cmp(&prio)) {
+ Ok(i) => i,
+ Err(i) => {
+ self.items.insert(i, (prio, VecDeque::new()));
+ i
+ }
+ };
+ self.items[pos_prio].1.push_back(item);
}
fn pop(&mut self) -> Option<SendQueueItem> {
- match self.items.pop_first() {
+ match self.items.pop_front() {
None => None,
Some((prio, mut items_at_prio)) => {
let ret = items_at_prio.pop_front();
if !items_at_prio.is_empty() {
- self.items.insert(prio, items_at_prio);
+ self.items.push_front((prio, items_at_prio));
}
ret.or_else(|| self.pop())
}