Skip to content
This repository has been archived by the owner on Nov 6, 2020. It is now read-only.

Remove redundant mut #6773

Merged
merged 5 commits into from
Oct 15, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions ethcore/src/account_provider/stores.rs
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ impl AddressBook {
/// Sets new name for given address.
pub fn set_name(&mut self, a: Address, name: String) {
{
let mut x = self.cache.entry(a)
let x = self.cache.entry(a)
.or_insert_with(|| AccountMeta {name: Default::default(), meta: "{}".to_owned(), uuid: None});
x.name = name;
}
Expand All @@ -74,7 +74,7 @@ impl AddressBook {
/// Sets new meta for given address.
pub fn set_meta(&mut self, a: Address, meta: String) {
{
let mut x = self.cache.entry(a)
let x = self.cache.entry(a)
.or_insert_with(|| AccountMeta {name: "Anonymous".to_owned(), meta: Default::default(), uuid: None});
x.meta = meta;
}
Expand Down Expand Up @@ -253,7 +253,7 @@ impl DappsSettingsStore {
/// Marks recent dapp as used
pub fn mark_dapp_used(&mut self, dapp: DappId) {
{
let mut entry = self.history.entry(dapp).or_insert_with(|| Default::default());
let entry = self.history.entry(dapp).or_insert_with(|| Default::default());
entry.last_accessed = self.time.get();
}
// Clear extraneous entries
Expand All @@ -280,7 +280,7 @@ impl DappsSettingsStore {
/// Sets accounts for specific dapp.
pub fn set_accounts(&mut self, id: DappId, accounts: Option<Vec<Address>>) {
{
let mut settings = self.settings.entry(id).or_insert_with(DappsSettings::default);
let settings = self.settings.entry(id).or_insert_with(DappsSettings::default);
settings.accounts = accounts;
}
self.settings.save(JsonSettings::write);
Expand All @@ -289,7 +289,7 @@ impl DappsSettingsStore {
/// Sets a default account for specific dapp.
pub fn set_default(&mut self, id: DappId, default: Address) {
{
let mut settings = self.settings.entry(id).or_insert_with(DappsSettings::default);
let settings = self.settings.entry(id).or_insert_with(DappsSettings::default);
settings.default = Some(default);
}
self.settings.save(JsonSettings::write);
Expand Down
2 changes: 1 addition & 1 deletion ethcore/src/engines/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -421,7 +421,7 @@ pub mod common {
.and_then(|_| fields.state.commit());

let block_author = fields.header.author().clone();
fields.traces.as_mut().map(move |mut traces| {
fields.traces.as_mut().map(move |traces| {
let mut tracer = ExecutiveTracer::default();
tracer.trace_reward(block_author, reward, RewardType::Block);
traces.push(tracer.drain())
Expand Down
2 changes: 1 addition & 1 deletion ethcore/src/executive.rs
Original file line number Diff line number Diff line change
Expand Up @@ -433,7 +433,7 @@ impl<'a, B: 'a + StateBackend> Executive<'a, B> {
// trace only top level calls to builtins to avoid DDoS attacks
if self.depth == 0 {
let mut trace_output = tracer.prepare_trace_output();
if let Some(mut out) = trace_output.as_mut() {
if let Some(out) = trace_output.as_mut() {
*out = output.to_owned();
}

Expand Down
6 changes: 3 additions & 3 deletions ethcore/src/miner/banning_queue.rs
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ impl BanningTransactionQueue {
/// queue.
fn ban_sender(&mut self, address: Address) -> bool {
let count = {
let mut count = self.senders_bans.entry(address).or_insert_with(|| 0);
let count = self.senders_bans.entry(address).or_insert_with(|| 0);
*count = count.saturating_add(1);
*count
};
Expand All @@ -169,7 +169,7 @@ impl BanningTransactionQueue {
/// Returns true if bans threshold has been reached.
fn ban_recipient(&mut self, address: Address) -> bool {
let count = {
let mut count = self.recipients_bans.entry(address).or_insert_with(|| 0);
let count = self.recipients_bans.entry(address).or_insert_with(|| 0);
*count = count.saturating_add(1);
*count
};
Expand All @@ -185,7 +185,7 @@ impl BanningTransactionQueue {
/// If bans threshold is reached all subsequent transactions to contracts with this codehash will be rejected.
/// Returns true if bans threshold has been reached.
fn ban_codehash(&mut self, code_hash: H256) -> bool {
let mut count = self.codes_bans.entry(code_hash).or_insert_with(|| 0);
let count = self.codes_bans.entry(code_hash).or_insert_with(|| 0);
*count = count.saturating_add(1);

match self.ban_threshold {
Expand Down
4 changes: 2 additions & 2 deletions ethcore/src/miner/transaction_queue.rs
Original file line number Diff line number Diff line change
Expand Up @@ -341,7 +341,7 @@ impl GasPriceQueue {
/// Remove an item from a BTreeMap/HashSet "multimap".
/// Returns true if the item was removed successfully.
pub fn remove(&mut self, gas_price: &U256, hash: &H256) -> bool {
if let Some(mut hashes) = self.backing.get_mut(gas_price) {
if let Some(hashes) = self.backing.get_mut(gas_price) {
let only_one_left = hashes.len() == 1;
if !only_one_left {
// Operation may be ok: only if hash is in gas-price's Set.
Expand Down Expand Up @@ -1225,7 +1225,7 @@ impl TransactionQueue {
if by_nonce.is_none() {
return;
}
let mut by_nonce = by_nonce.expect("None is tested in early-exit condition above; qed");
let by_nonce = by_nonce.expect("None is tested in early-exit condition above; qed");
while let Some(order) = by_nonce.remove(&current_nonce) {
// remove also from priority and gas_price
self.future.by_priority.remove(&order);
Expand Down
2 changes: 1 addition & 1 deletion ethcore/src/state/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -962,7 +962,7 @@ impl<B: Backend> State<B> {

// at this point the entry is guaranteed to be in the cache.
Ok(RefMut::map(self.cache.borrow_mut(), |c| {
let mut entry = c.get_mut(a).expect("entry known to exist in the cache; qed");
let entry = c.get_mut(a).expect("entry known to exist in the cache; qed");

match &mut entry.account {
&mut Some(ref mut acc) => not_default(acc),
Expand Down
2 changes: 1 addition & 1 deletion ethcore/src/state_db.rs
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,7 @@ impl StateDB {
pub fn sync_cache(&mut self, enacted: &[H256], retracted: &[H256], is_best: bool) {
trace!("sync_cache id = (#{:?}, {:?}), parent={:?}, best={}", self.commit_number, self.commit_hash, self.parent_hash, is_best);
let mut cache = self.account_cache.lock();
let mut cache = &mut *cache;
let cache = &mut *cache;

// Purge changes from re-enacted and retracted blocks.
// Filter out commiting block if any.
Expand Down
2 changes: 1 addition & 1 deletion ethcore/src/verification/queue/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -522,7 +522,7 @@ impl<K: Kind> VerificationQueue<K> {
return;
}
let mut verified_lock = self.verification.verified.lock();
let mut verified = &mut *verified_lock;
let verified = &mut *verified_lock;
let mut bad = self.verification.bad.lock();
let mut processing = self.processing.write();
bad.reserve(hashes.len());
Expand Down
6 changes: 3 additions & 3 deletions ethstore/src/dir/memory.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ impl KeyDirectory for MemoryDirectory {

fn update(&self, account: SafeAccount) -> Result<SafeAccount, Error> {
let mut lock = self.accounts.write();
let mut accounts = lock.entry(account.address.clone()).or_insert_with(Vec::new);
let accounts = lock.entry(account.address.clone()).or_insert_with(Vec::new);
// If the filename is the same we just need to replace the entry
accounts.retain(|acc| acc.filename != account.filename);
accounts.push(account.clone());
Expand All @@ -44,14 +44,14 @@ impl KeyDirectory for MemoryDirectory {

fn insert(&self, account: SafeAccount) -> Result<SafeAccount, Error> {
let mut lock = self.accounts.write();
let mut accounts = lock.entry(account.address.clone()).or_insert_with(Vec::new);
let accounts = lock.entry(account.address.clone()).or_insert_with(Vec::new);
accounts.push(account.clone());
Ok(account)
}

fn remove(&self, account: &SafeAccount) -> Result<(), Error> {
let mut accounts = self.accounts.write();
let is_empty = if let Some(mut accounts) = accounts.get_mut(&account.address) {
let is_empty = if let Some(accounts) = accounts.get_mut(&account.address) {
if let Some(position) = accounts.iter().position(|acc| acc == account) {
accounts.remove(position);
}
Expand Down
2 changes: 1 addition & 1 deletion ethstore/src/ethstore.rs
Original file line number Diff line number Diff line change
Expand Up @@ -358,7 +358,7 @@ impl EthMultiStore {

// update cache
let mut cache = self.cache.write();
let mut accounts = cache.entry(account_ref.clone()).or_insert_with(Vec::new);
let accounts = cache.entry(account_ref.clone()).or_insert_with(Vec::new);
// Remove old account
accounts.retain(|acc| acc != &old);
// And push updated to the end
Expand Down
2 changes: 1 addition & 1 deletion hw/src/ledger.rs
Original file line number Diff line number Diff line change
Expand Up @@ -255,7 +255,7 @@ impl Manager {
let mut chunk_size = if chunk_index == 0 { 12 } else { 5 };
let size = min(64 - chunk_size, data.len() - offset);
{
let mut chunk = &mut hid_chunk[HID_PREFIX_ZERO..];
let chunk = &mut hid_chunk[HID_PREFIX_ZERO..];
&mut chunk[0..5].copy_from_slice(&[0x01, 0x01, APDU_TAG, (chunk_index >> 8) as u8, (chunk_index & 0xff) as u8 ]);

if chunk_index == 0 {
Expand Down
2 changes: 1 addition & 1 deletion rpc/src/authcodes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@ impl<T: TimeProvider> AuthCodes<T> {
}

// look for code
for mut code in &mut self.codes {
for code in &mut self.codes {
if &as_token(&code.code) == hash {
code.last_used_at = Some(time::Duration::from_secs(now));
return true;
Expand Down
2 changes: 1 addition & 1 deletion rpc/src/v1/extractors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ impl ws::RequestMiddleware for WsExtractor {
}

fn add_security_headers(res: &mut ws::ws::Response) {
let mut headers = res.headers_mut();
let headers = res.headers_mut();
headers.push(("X-Frame-Options".into(), b"SAMEORIGIN".to_vec()));
headers.push(("X-XSS-Protection".into(), b"1; mode=block".to_vec()));
headers.push(("X-Content-Type-Options".into(), b"nosniff".to_vec()));
Expand Down
10 changes: 5 additions & 5 deletions sync/src/chain.rs
Original file line number Diff line number Diff line change
Expand Up @@ -459,7 +459,7 @@ impl ChainSync {

/// Updates transactions were received by a peer
pub fn transactions_received(&mut self, hashes: Vec<H256>, peer_id: PeerId) {
if let Some(mut peer_info) = self.peers.get_mut(&peer_id) {
if let Some(peer_info) = self.peers.get_mut(&peer_id) {
peer_info.last_sent_transactions.extend(&hashes);
}
}
Expand Down Expand Up @@ -730,7 +730,7 @@ impl ChainSync {
}

let result = {
let mut downloader = match block_set {
let downloader = match block_set {
BlockSet::NewBlocks => &mut self.new_blocks,
BlockSet::OldBlocks => {
match self.old_blocks {
Expand Down Expand Up @@ -795,7 +795,7 @@ impl ChainSync {
else
{
let result = {
let mut downloader = match block_set {
let downloader = match block_set {
BlockSet::NewBlocks => &mut self.new_blocks,
BlockSet::OldBlocks => match self.old_blocks {
None => {
Expand Down Expand Up @@ -849,7 +849,7 @@ impl ChainSync {
else
{
let result = {
let mut downloader = match block_set {
let downloader = match block_set {
BlockSet::NewBlocks => &mut self.new_blocks,
BlockSet::OldBlocks => match self.old_blocks {
None => {
Expand Down Expand Up @@ -2186,7 +2186,7 @@ impl ChainSync {
// Select random peer to re-broadcast transactions to.
let peer = random::new().gen_range(0, self.peers.len());
trace!(target: "sync", "Re-broadcasting transactions to a random peer.");
self.peers.values_mut().nth(peer).map(|mut peer_info|
self.peers.values_mut().nth(peer).map(|peer_info|
peer_info.last_sent_transactions.clear()
);
}
Expand Down
4 changes: 2 additions & 2 deletions sync/src/transactions_stats.rs
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,8 @@ impl TransactionsStats {
/// Increases number of propagations to given `enodeid`.
pub fn propagated(&mut self, hash: &H256, enode_id: Option<NodeId>, current_block_num: BlockNumber) {
let enode_id = enode_id.unwrap_or_default();
let mut stats = self.pending_transactions.entry(*hash).or_insert_with(|| Stats::new(current_block_num));
let mut count = stats.propagated_to.entry(enode_id).or_insert(0);
let stats = self.pending_transactions.entry(*hash).or_insert_with(|| Stats::new(current_block_num));
let count = stats.propagated_to.entry(enode_id).or_insert(0);
*count = count.saturating_add(1);
}

Expand Down
6 changes: 3 additions & 3 deletions util/kvdb/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -254,20 +254,20 @@ impl KeyValueDB for InMemory {
for op in ops {
match op {
DBOp::Insert { col, key, value } => {
if let Some(mut col) = columns.get_mut(&col) {
if let Some(col) = columns.get_mut(&col) {
col.insert(key.into_vec(), value);
}
},
DBOp::InsertCompressed { col, key, value } => {
if let Some(mut col) = columns.get_mut(&col) {
if let Some(col) = columns.get_mut(&col) {
let compressed = UntrustedRlp::new(&value).compress(RlpType::Blocks);
let mut value = DBValue::new();
value.append_slice(&compressed);
col.insert(key.into_vec(), value);
}
},
DBOp::Delete { col, key } => {
if let Some(mut col) = columns.get_mut(&col) {
if let Some(col) = columns.get_mut(&col) {
col.remove(&*key);
}
},
Expand Down
6 changes: 3 additions & 3 deletions util/network/src/discovery.rs
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ impl Discovery {
trace!(target: "discovery", "Inserting {:?}", &e);
let id_hash = keccak(e.id);
let ping = {
let mut bucket = &mut self.node_buckets[Discovery::distance(&self.id_hash, &id_hash) as usize];
let bucket = &mut self.node_buckets[Discovery::distance(&self.id_hash, &id_hash) as usize];
let updated = if let Some(node) = bucket.nodes.iter_mut().find(|n| n.address.id == e.id) {
node.address = e.clone();
node.timeout = None;
Expand All @@ -169,7 +169,7 @@ impl Discovery {

if bucket.nodes.len() > BUCKET_SIZE {
//ping least active node
let mut last = bucket.nodes.back_mut().expect("Last item is always present when len() > 0");
let last = bucket.nodes.back_mut().expect("Last item is always present when len() > 0");
last.timeout = Some(time::precise_time_ns());
Some(last.address.endpoint.clone())
} else { None }
Expand All @@ -180,7 +180,7 @@ impl Discovery {
}

fn clear_ping(&mut self, id: &NodeId) {
let mut bucket = &mut self.node_buckets[Discovery::distance(&self.id_hash, &keccak(id)) as usize];
let bucket = &mut self.node_buckets[Discovery::distance(&self.id_hash, &keccak(id)) as usize];
if let Some(node) = bucket.nodes.iter_mut().find(|n| &n.address.id == id) {
node.timeout = None;
}
Expand Down
2 changes: 1 addition & 1 deletion util/network/src/node_table.rs
Original file line number Diff line number Diff line change
Expand Up @@ -253,7 +253,7 @@ impl NodeTable {
/// Apply table changes coming from discovery
pub fn update(&mut self, mut update: TableUpdates, reserved: &HashSet<NodeId>) {
for (_, node) in update.added.drain() {
let mut entry = self.nodes.entry(node.id.clone()).or_insert_with(|| Node::new(node.id.clone(), node.endpoint.clone()));
let entry = self.nodes.entry(node.id.clone()).or_insert_with(|| Node::new(node.id.clone(), node.endpoint.clone()));
entry.endpoint = node.endpoint;
}
for r in update.removed {
Expand Down
2 changes: 1 addition & 1 deletion util/table/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ impl<Row, Col, Val> Table<Row, Col, Val>
if let None = row_map {
return None;
}
let mut row_map = row_map.unwrap();
let row_map = row_map.unwrap();
let val = row_map.remove(col);
(val, row_map.is_empty())
};
Expand Down