Skip to content

Commit 4738c34

Browse files
committed
Fix string to empty string comparison and len zero warnings
Signed-off-by: Jacinta Ferrant <[email protected]>
1 parent 0ee5d7c commit 4738c34

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

81 files changed

+380
-375
lines changed

stackslib/src/burnchains/affirmation.rs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -378,6 +378,10 @@ impl AffirmationMap {
378378
self.affirmations.len()
379379
}
380380

381+
pub fn is_empty(&self) -> bool {
382+
self.affirmations.is_empty()
383+
}
384+
381385
pub fn as_slice(&self) -> &[AffirmationMapEntry] {
382386
&self.affirmations
383387
}
@@ -876,7 +880,7 @@ fn inner_find_heaviest_block_commit_ptr(
876880
test_debug!("ancestors = {:?}", &ancestors);
877881
test_debug!("ancestor_confirmations = {:?}", &ancestor_confirmations);
878882

879-
if ancestor_confirmations.len() == 0 {
883+
if ancestor_confirmations.is_empty() {
880884
// empty prepare phase
881885
test_debug!("Prepare-phase has no block-commits");
882886
return None;

stackslib/src/burnchains/bitcoin/address.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -317,7 +317,7 @@ impl SegwitBitcoinAddress {
317317
None
318318
}?;
319319

320-
if quintets.len() == 0 || quintets.len() > 65 {
320+
if quintets.is_empty() || quintets.len() > 65 {
321321
test_debug!("Invalid prog length: {}", quintets.len());
322322
return None;
323323
}

stackslib/src/burnchains/bitcoin/bits.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ impl BitcoinTxInputStructured {
9393
segwit: bool,
9494
input_txid: (Txid, u32),
9595
) -> Option<BitcoinTxInputStructured> {
96-
if num_sigs < 1 || pubkey_pushbytes.len() < 1 || pubkey_pushbytes.len() < num_sigs {
96+
if num_sigs < 1 || pubkey_pushbytes.is_empty() || pubkey_pushbytes.len() < num_sigs {
9797
test_debug!(
9898
"Not a multisig script: num_sigs = {}, num_pubkeys <= {}",
9999
num_sigs,
@@ -153,7 +153,7 @@ impl BitcoinTxInputStructured {
153153
pubkey_vecs: &[Vec<u8>],
154154
input_txid: (Txid, u32),
155155
) -> Option<BitcoinTxInputStructured> {
156-
if num_sigs < 1 || pubkey_vecs.len() < 1 || pubkey_vecs.len() < num_sigs {
156+
if num_sigs < 1 || pubkey_vecs.is_empty() || pubkey_vecs.len() < num_sigs {
157157
test_debug!(
158158
"Not a multisig script: num_sigs = {}, num_pubkeys <= {}",
159159
num_sigs,

stackslib/src/burnchains/bitcoin/blocks.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -381,7 +381,7 @@ impl BitcoinBlockParser {
381381
tx: &Transaction,
382382
epoch_id: StacksEpochId,
383383
) -> Option<Vec<BitcoinTxOutput>> {
384-
if tx.output.len() == 0 {
384+
if tx.output.is_empty() {
385385
return None;
386386
}
387387

stackslib/src/burnchains/bitcoin/indexer.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -705,7 +705,7 @@ impl BitcoinIndexer {
705705
e
706706
})?;
707707

708-
if reorg_headers.len() == 0 {
708+
if reorg_headers.is_empty() {
709709
// chain shrank considerably
710710
info!(
711711
"Missing Bitcoin headers in block range {}-{} -- did the Bitcoin chain shrink?",
@@ -736,7 +736,7 @@ impl BitcoinIndexer {
736736
})?;
737737

738738
assert!(
739-
canonical_headers.len() > 0,
739+
!canonical_headers.is_empty(),
740740
"BUG: uninitialized canonical SPV headers DB"
741741
);
742742

@@ -1379,7 +1379,7 @@ mod test {
13791379
spv_client
13801380
.insert_block_headers_before(start_block - 1, hdrs)
13811381
.unwrap();
1382-
} else if hdrs.len() > 0 {
1382+
} else if !hdrs.is_empty() {
13831383
test_debug!("insert at {}: {:?}", 0, &hdrs);
13841384
spv_client.test_write_block_headers(0, hdrs).unwrap();
13851385
}
@@ -1552,7 +1552,7 @@ mod test {
15521552
spv_client
15531553
.insert_block_headers_before(start_block - 1, hdrs)
15541554
.unwrap();
1555-
} else if hdrs.len() > 0 {
1555+
} else if !hdrs.is_empty() {
15561556
test_debug!("insert at {}: {:?}", 0, &hdrs);
15571557
spv_client.test_write_block_headers(0, hdrs).unwrap();
15581558
}

stackslib/src/burnchains/bitcoin/network.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -355,7 +355,7 @@ impl BitcoinIndexer {
355355

356356
/// Send a GetData message
357357
pub fn send_getdata(&mut self, block_hashes: &Vec<Sha256dHash>) -> Result<(), btc_error> {
358-
assert!(block_hashes.len() > 0);
358+
assert!(!block_hashes.is_empty());
359359
let getdata_invs = block_hashes
360360
.iter()
361361
.map(|h| btc_message_blockdata::Inventory {

stackslib/src/burnchains/bitcoin/spv.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -529,7 +529,7 @@ impl SpvClient {
529529
headers: &Vec<LoneBlockHeader>,
530530
check_txcount: bool,
531531
) -> Result<(), btc_error> {
532-
if headers.len() == 0 {
532+
if headers.is_empty() {
533533
return Ok(());
534534
}
535535

@@ -945,7 +945,7 @@ impl SpvClient {
945945
) -> Result<(), btc_error> {
946946
assert!(self.readwrite, "SPV header DB is open read-only");
947947

948-
if block_headers.len() == 0 {
948+
if block_headers.is_empty() {
949949
// no-op
950950
return Ok(());
951951
}
@@ -996,7 +996,7 @@ impl SpvClient {
996996
block_headers: Vec<LoneBlockHeader>,
997997
) -> Result<(), btc_error> {
998998
assert!(self.readwrite, "SPV header DB is open read-only");
999-
if block_headers.len() == 0 {
999+
if block_headers.is_empty() {
10001000
// no-op
10011001
return Ok(());
10021002
}
@@ -1137,7 +1137,7 @@ impl SpvClient {
11371137
]);
11381138
let max_target_bits = BlockHeader::compact_target_from_u256(&max_target);
11391139

1140-
let parent_header = if headers_in_range.len() > 0 {
1140+
let parent_header = if !headers_in_range.is_empty() {
11411141
headers_in_range[0]
11421142
} else {
11431143
match self.read_block_header(current_header_height - 1)? {

stackslib/src/burnchains/burnchain.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,7 @@ impl BurnchainStateTransition {
130130

131131
block_total_burns.sort();
132132

133-
if block_total_burns.len() == 0 {
133+
if block_total_burns.is_empty() {
134134
return Some(0);
135135
} else if block_total_burns.len() == 1 {
136136
return Some(block_total_burns[0]);

stackslib/src/burnchains/db.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -452,7 +452,7 @@ impl<'a> BurnchainDBTransaction<'a> {
452452
})
453453
.collect()
454454
};
455-
if commits.len() == 0 {
455+
if commits.is_empty() {
456456
test_debug!("No block-commits for block {}", hdr.block_height);
457457
return Ok(());
458458
}

stackslib/src/burnchains/tests/burnchain.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -574,7 +574,7 @@ fn test_process_block_ops() {
574574
acc
575575
});
576576

577-
let next_sortition = block_ops_124.len() > 0 && burn_total > 0;
577+
let next_sortition = !block_ops_124.is_empty() && burn_total > 0;
578578

579579
let mut block_124_snapshot = BlockSnapshot {
580580
accumulated_coinbase_ustx: 400_000_000,

0 commit comments

Comments
 (0)