Replaced slow vec initialization, and dual calls to hashmap
This commit is contained in:
parent
a148e06736
commit
16eb81e1f7
|
@ -543,8 +543,8 @@ impl Decodable for [u16; 8] {
|
|||
#[inline]
|
||||
fn consensus_decode<D: io::Read>(mut d: D) -> Result<Self, Error> {
|
||||
let mut res = [0; 8];
|
||||
for i in 0..8 {
|
||||
res[i] = Decodable::consensus_decode(&mut d)?;
|
||||
for item in &mut res {
|
||||
*item = Decodable::consensus_decode(&mut d)?;
|
||||
}
|
||||
Ok(res)
|
||||
}
|
||||
|
|
|
@ -111,7 +111,7 @@ impl GetBlocksMessage {
|
|||
pub fn new(locator_hashes: Vec<BlockHash>, stop_hash: BlockHash) -> GetBlocksMessage {
|
||||
GetBlocksMessage {
|
||||
version: constants::PROTOCOL_VERSION,
|
||||
locator_hashes: locator_hashes.clone(),
|
||||
locator_hashes: locator_hashes,
|
||||
stop_hash: stop_hash
|
||||
}
|
||||
}
|
||||
|
|
|
@ -119,12 +119,12 @@ macro_rules! impl_psbt_insert_pair {
|
|||
if !$raw_key.key.is_empty() {
|
||||
let key_val: $keyed_key_type = ::util::psbt::serialize::Deserialize::deserialize(&$raw_key.key)?;
|
||||
|
||||
if $slf.$keyed_name.contains_key(&key_val) {
|
||||
return Err(::util::psbt::Error::DuplicateKey($raw_key).into());
|
||||
} else {
|
||||
match $slf.$keyed_name.entry(key_val) {
|
||||
::std::collections::btree_map::Entry::Vacant(empty_key) => {
|
||||
let val: $keyed_value_type = ::util::psbt::serialize::Deserialize::deserialize(&$raw_value)?;
|
||||
|
||||
$slf.$keyed_name.insert(key_val, val);
|
||||
empty_key.insert(val);
|
||||
}
|
||||
::std::collections::btree_map::Entry::Occupied(_) => return Err(::util::psbt::Error::DuplicateKey($raw_key).into()),
|
||||
}
|
||||
} else {
|
||||
return Err(::util::psbt::Error::InvalidKey($raw_key).into());
|
||||
|
|
|
@ -13,6 +13,7 @@
|
|||
//
|
||||
|
||||
use std::collections::BTreeMap;
|
||||
use std::collections::btree_map::Entry;
|
||||
use std::io::{self, Cursor};
|
||||
|
||||
use blockdata::transaction::Transaction;
|
||||
|
@ -60,15 +61,10 @@ impl Map for Global {
|
|||
} = pair;
|
||||
|
||||
match raw_key.type_value {
|
||||
0u8 => {
|
||||
return Err(Error::DuplicateKey(raw_key).into());
|
||||
}
|
||||
_ => {
|
||||
if self.unknown.contains_key(&raw_key) {
|
||||
return Err(Error::DuplicateKey(raw_key).into());
|
||||
} else {
|
||||
self.unknown.insert(raw_key, raw_value);
|
||||
}
|
||||
0u8 => return Err(Error::DuplicateKey(raw_key).into()),
|
||||
_ => match self.unknown.entry(raw_key) {
|
||||
Entry::Vacant(empty_key) => {empty_key.insert(raw_value);},
|
||||
Entry::Occupied(k) => return Err(Error::DuplicateKey(k.key().clone()).into()),
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -158,12 +154,9 @@ impl Decodable for Global {
|
|||
return Err(Error::InvalidKey(pair.key).into())
|
||||
}
|
||||
}
|
||||
_ => {
|
||||
if unknowns.contains_key(&pair.key) {
|
||||
return Err(Error::DuplicateKey(pair.key).into());
|
||||
} else {
|
||||
unknowns.insert(pair.key, pair.value);
|
||||
}
|
||||
_ => match unknowns.entry(pair.key) {
|
||||
Entry::Vacant(empty_key) => {empty_key.insert(pair.value);},
|
||||
Entry::Occupied(k) => return Err(Error::DuplicateKey(k.key().clone()).into()),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -112,12 +112,9 @@ impl Map for Input {
|
|||
self.hd_keypaths <= <raw_key: PublicKey>|<raw_value: (Fingerprint, DerivationPath)>
|
||||
}
|
||||
}
|
||||
_ => {
|
||||
if self.unknown.contains_key(&raw_key) {
|
||||
return Err(Error::DuplicateKey(raw_key).into());
|
||||
} else {
|
||||
self.unknown.insert(raw_key, raw_value);
|
||||
}
|
||||
_ => match self.unknown.entry(raw_key) {
|
||||
::std::collections::btree_map::Entry::Vacant(empty_key) => {empty_key.insert(raw_value);},
|
||||
::std::collections::btree_map::Entry::Occupied(k) => return Err(Error::DuplicateKey(k.key().clone()).into()),
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -13,6 +13,7 @@
|
|||
//
|
||||
|
||||
use std::collections::BTreeMap;
|
||||
use std::collections::btree_map::Entry;
|
||||
|
||||
use blockdata::script::Script;
|
||||
use consensus::encode;
|
||||
|
@ -61,12 +62,9 @@ impl Map for Output {
|
|||
self.hd_keypaths <= <raw_key: PublicKey>|<raw_value: (Fingerprint, DerivationPath)>
|
||||
}
|
||||
}
|
||||
_ => {
|
||||
if self.unknown.contains_key(&raw_key) {
|
||||
return Err(Error::DuplicateKey(raw_key).into());
|
||||
} else {
|
||||
self.unknown.insert(raw_key, raw_value);
|
||||
}
|
||||
_ => match self.unknown.entry(raw_key) {
|
||||
Entry::Vacant(empty_key) => {empty_key.insert(raw_value);},
|
||||
Entry::Occupied(k) => return Err(Error::DuplicateKey(k.key().clone()).into()),
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue