mirror of
https://github.com/YGGverse/aquatic.git
synced 2026-04-01 10:15:31 +00:00
aquatic_http: request from path: remove from map to avoid some clones
change: [-3.8362% -3.2346% -2.5437%] (p = 0.00 < 0.01) Performance has improved.
This commit is contained in:
parent
ca8d278a03
commit
b17c9999f0
5 changed files with 1010 additions and 1010 deletions
|
|
@ -60,7 +60,7 @@ impl Request {
|
|||
)?;
|
||||
|
||||
if location == "/announce" {
|
||||
let numwant = if let Some(s) = data.get("numwant"){
|
||||
let numwant = if let Some(s) = data.remove("numwant"){
|
||||
let numwant = s.parse::<usize>()
|
||||
.map_err(|err|
|
||||
anyhow::anyhow!("parse 'numwant': {}", err)
|
||||
|
|
@ -70,12 +70,12 @@ impl Request {
|
|||
} else {
|
||||
None
|
||||
};
|
||||
let key = if let Some(s) = data.get("key"){
|
||||
let key = if let Some(s) = data.remove("key"){
|
||||
if s.len() > 100 {
|
||||
return Err(anyhow::anyhow!("'key' is too long"))
|
||||
}
|
||||
|
||||
Some(s.clone())
|
||||
Some(s)
|
||||
} else {
|
||||
None
|
||||
};
|
||||
|
|
@ -89,18 +89,18 @@ impl Request {
|
|||
.with_context(|| "no peer_id")
|
||||
.and_then(|s| deserialize_20_bytes(s))
|
||||
.map(PeerId)?,
|
||||
port: data.get("port")
|
||||
port: data.remove("port")
|
||||
.with_context(|| "no port")
|
||||
.and_then(|s| s.parse()
|
||||
.map_err(|err| anyhow::anyhow!("parse 'port': {}", err)))?,
|
||||
bytes_left: data.get("left")
|
||||
bytes_left: data.remove("left")
|
||||
.with_context(|| "no left")
|
||||
.and_then(|s| s.parse()
|
||||
.map_err(|err| anyhow::anyhow!("parse 'left': {}", err)))?,
|
||||
event: data.get("event")
|
||||
event: data.remove("event")
|
||||
.and_then(|s| s.parse().ok())
|
||||
.unwrap_or_default(),
|
||||
compact: data.get("compact")
|
||||
compact: data.remove("compact")
|
||||
.map(|s| s == "1")
|
||||
.unwrap_or(true),
|
||||
numwant,
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue