Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Replace Vec References with slices in function inputs #3535

Merged
merged 8 commits into from
Feb 9, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Original file line number Diff line number Diff line change
Expand Up @@ -229,7 +229,7 @@ pub struct ContractInterfaceFunctionArg {
}

impl ContractInterfaceFunctionArg {
pub fn from_function_args(fnArgs: &Vec<FunctionArg>) -> Vec<ContractInterfaceFunctionArg> {
pub fn from_function_args(fnArgs: &[FunctionArg]) -> Vec<ContractInterfaceFunctionArg> {
let mut args: Vec<ContractInterfaceFunctionArg> = Vec::new();
for ref fnArg in fnArgs.iter() {
args.push(ContractInterfaceFunctionArg {
Expand Down
2 changes: 1 addition & 1 deletion clarity/src/vm/ast/parser/v1.rs
Original file line number Diff line number Diff line change
Expand Up @@ -491,7 +491,7 @@ enum ParseStackItem {
}

fn handle_expression(
parse_stack: &mut Vec<(Vec<ParseStackItem>, u32, u32, ParseContext)>,
parse_stack: &mut [(Vec<ParseStackItem>, u32, u32, ParseContext)],
outputs: &mut Vec<PreSymbolicExpression>,
expr: PreSymbolicExpression,
) {
Expand Down
2 changes: 1 addition & 1 deletion clarity/src/vm/database/clarity_store.rs
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ pub type SpecialCaseHandler = &'static dyn Fn(
// the invoked function name
&str,
// the function parameters
&Vec<Value>,
&[Value],
// the result of the function call
&Value,
) -> Result<()>;
Expand Down
4 changes: 2 additions & 2 deletions clarity/src/vm/database/key_value_wrapper.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,10 @@ type RollbackValueCheck = String;
type RollbackValueCheck = ();

#[cfg(not(rollback_value_check))]
fn rollback_value_check(_value: &String, _check: &RollbackValueCheck) {}
fn rollback_value_check(_value: &str, _check: &RollbackValueCheck) {}

#[cfg(not(rollback_value_check))]
fn rollback_edits_push<T>(edits: &mut Vec<(T, RollbackValueCheck)>, key: T, _value: &String) {
fn rollback_edits_push<T>(edits: &mut Vec<(T, RollbackValueCheck)>, key: T, _value: &str) {
edits.push((key, ()));
}
// this function is used to check the lookup map when committing at the "bottom" of the
Expand Down
6 changes: 3 additions & 3 deletions src/burnchains/affirmation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -621,7 +621,7 @@ pub fn read_prepare_phase_commits<B: BurnchainHeaderReader>(
pub fn read_parent_block_commits<B: BurnchainHeaderReader>(
burnchain_tx: &BurnchainDBTransaction,
indexer: &B,
prepare_phase_ops: &Vec<Vec<LeaderBlockCommitOp>>,
prepare_phase_ops: &[Vec<LeaderBlockCommitOp>],
) -> Result<Vec<LeaderBlockCommitOp>, Error> {
let mut parents = HashMap::new();
for ops in prepare_phase_ops.iter() {
Expand Down Expand Up @@ -691,7 +691,7 @@ pub fn read_parent_block_commits<B: BurnchainHeaderReader>(
/// Given a list of prepare-phase block-commits, and a list of parent commits, filter out and remove
/// the prepare-phase commits that _don't_ have a parent.
pub fn filter_orphan_block_commits(
parents: &Vec<LeaderBlockCommitOp>,
parents: &[LeaderBlockCommitOp],
prepare_phase_ops: Vec<Vec<LeaderBlockCommitOp>>,
) -> Vec<Vec<LeaderBlockCommitOp>> {
let mut parent_set = HashSet::new();
Expand Down Expand Up @@ -773,7 +773,7 @@ pub fn filter_missed_block_commits(
/// exists at all.
/// Returns None otherwise
fn inner_find_heaviest_block_commit_ptr(
prepare_phase_ops: &Vec<Vec<LeaderBlockCommitOp>>,
prepare_phase_ops: &[Vec<LeaderBlockCommitOp>],
anchor_threshold: u32,
) -> Option<(PoxAnchorPtr, BTreeMap<(u64, u32), (u64, u32)>)> {
// sanity check -- must be in order by block height and vtxindex
Expand Down
4 changes: 2 additions & 2 deletions src/burnchains/bitcoin/bits.rs
Original file line number Diff line number Diff line change
Expand Up @@ -498,12 +498,12 @@ impl BitcoinTxInputRaw {

pub fn from_bitcoin_witness_script_sig(
script_sig: &Script,
witness: &Vec<Vec<u8>>,
witness: &[Vec<u8>],
input_txid: (Txid, u32),
) -> BitcoinTxInputRaw {
BitcoinTxInputRaw {
scriptSig: script_sig.clone().into_bytes(),
witness: witness.clone(),
witness: witness.to_owned(),
tx_ref: input_txid,
}
}
Expand Down
4 changes: 2 additions & 2 deletions src/burnchains/bitcoin/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -234,14 +234,14 @@ impl BitcoinBlock {
height: u64,
hash: &BurnchainHeaderHash,
parent: &BurnchainHeaderHash,
txs: &Vec<BitcoinTransaction>,
txs: &[BitcoinTransaction],
timestamp: u64,
) -> BitcoinBlock {
BitcoinBlock {
block_height: height,
block_hash: hash.clone(),
parent_block_hash: parent.clone(),
txs: txs.clone(),
txs: txs.to_owned(),
timestamp: timestamp,
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/burnchains/bitcoin/spv.rs
Original file line number Diff line number Diff line change
Expand Up @@ -342,7 +342,7 @@ impl SpvClient {
}

/// Calculate the total work over a given interval of headers.
fn get_interval_work(interval_headers: &Vec<LoneBlockHeader>) -> Uint256 {
fn get_interval_work(interval_headers: &[LoneBlockHeader]) -> Uint256 {
let mut work = Uint256::from_u64(0);
for hdr in interval_headers.iter() {
work = work + hdr.header.work();
Expand Down
2 changes: 1 addition & 1 deletion src/burnchains/burnchain.rs
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ impl BurnchainStateTransition {
burnchain: &Burnchain,
parent_snapshot: &BlockSnapshot,
block_ops: &Vec<BlockstackOperationType>,
missed_commits: &Vec<MissedBlockCommit>,
missed_commits: &[MissedBlockCommit],
) -> Result<BurnchainStateTransition, burnchain_error> {
// block commits and support burns discovered in this block.
let mut block_commits: Vec<LeaderBlockCommitOp> = vec![];
Expand Down
2 changes: 1 addition & 1 deletion src/burnchains/db.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1284,7 +1284,7 @@ impl BurnchainDB {
burnchain: &Burnchain,
indexer: &B,
block_header: &BurnchainBlockHeader,
blockstack_ops: &Vec<BlockstackOperationType>,
blockstack_ops: &[BlockstackOperationType],
) -> Result<(), BurnchainError> {
let db_tx = self.tx_begin()?;

Expand Down
4 changes: 2 additions & 2 deletions src/chainstate/burn/db/sortdb.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5046,7 +5046,7 @@ impl<'a> SortitionHandleTx<'a> {
&mut self,
parent_snapshot: &mut BlockSnapshot,
snapshot: &BlockSnapshot,
block_ops: &Vec<BlockstackOperationType>,
block_ops: &[BlockstackOperationType],
next_pox_info: Option<RewardCycleInfo>,
recipient_info: Option<&RewardSetInfo>,
initialize_bonus: Option<InitialMiningBonus>,
Expand Down Expand Up @@ -5633,7 +5633,7 @@ impl<'a> SortitionHandleTx<'a> {
}

impl ChainstateDB for SortitionDB {
fn backup(_backup_path: &String) -> Result<(), db_error> {
fn backup(_backup_path: &str) -> Result<(), db_error> {
return Err(db_error::NotImplemented);
}
}
Expand Down
4 changes: 2 additions & 2 deletions src/chainstate/burn/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -216,7 +216,7 @@ pub trait ConsensusHashExtensions {
burn_header_hash: &BurnchainHeaderHash,
opshash: &OpsHash,
total_burn: u64,
prev_consensus_hashes: &Vec<ConsensusHash>,
prev_consensus_hashes: &[ConsensusHash],
pox_id: &PoxId,
) -> ConsensusHash;

Expand Down Expand Up @@ -255,7 +255,7 @@ impl ConsensusHashExtensions for ConsensusHash {
burn_header_hash: &BurnchainHeaderHash,
opshash: &OpsHash,
total_burn: u64,
prev_consensus_hashes: &Vec<ConsensusHash>,
prev_consensus_hashes: &[ConsensusHash],
pox_id: &PoxId,
) -> ConsensusHash {
// NOTE: unlike stacks v1, we calculate the next consensus hash
Expand Down
4 changes: 2 additions & 2 deletions src/chainstate/coordinator/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -142,10 +142,10 @@ pub trait BlockEventDispatcher {
&self,
block: &StacksBlock,
metadata: &StacksHeaderInfo,
receipts: &Vec<StacksTransactionReceipt>,
receipts: &[StacksTransactionReceipt],
parent: &StacksBlockId,
winner_txid: Txid,
matured_rewards: &Vec<MinerReward>,
matured_rewards: &[MinerReward],
matured_rewards_info: Option<&MinerRewardInfo>,
parent_burn_block_hash: BurnchainHeaderHash,
parent_burn_block_height: u32,
Expand Down
4 changes: 2 additions & 2 deletions src/chainstate/coordinator/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -418,10 +418,10 @@ impl BlockEventDispatcher for NullEventDispatcher {
&self,
_block: &StacksBlock,
_metadata: &StacksHeaderInfo,
_receipts: &Vec<StacksTransactionReceipt>,
_receipts: &[StacksTransactionReceipt],
_parent: &StacksBlockId,
_winner_txid: Txid,
_rewards: &Vec<MinerReward>,
_rewards: &[MinerReward],
_rewards_info: Option<&MinerRewardInfo>,
_parent_burn_block_hash: BurnchainHeaderHash,
_parent_burn_block_height: u32,
Expand Down
2 changes: 1 addition & 1 deletion src/chainstate/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ use crate::util_lib::db;
use crate::util_lib::db::Error as db_error;

pub trait ChainstateDB {
fn backup(backup_path: &String) -> Result<(), db_error>;
fn backup(backup_path: &str) -> Result<(), db_error>;
}

// needs to come _after_ the macro def above, since they both use this macro
Expand Down
4 changes: 2 additions & 2 deletions src/chainstate/stacks/auth.rs
Original file line number Diff line number Diff line change
Expand Up @@ -912,7 +912,7 @@ impl TransactionAuth {
}
}

pub fn from_p2sh(privks: &Vec<StacksPrivateKey>, num_sigs: u16) -> Option<TransactionAuth> {
pub fn from_p2sh(privks: &[StacksPrivateKey], num_sigs: u16) -> Option<TransactionAuth> {
let mut pubks = vec![];
for privk in privks.iter() {
pubks.push(StacksPublicKey::from_private(privk));
Expand All @@ -933,7 +933,7 @@ impl TransactionAuth {
}
}

pub fn from_p2wsh(privks: &Vec<StacksPrivateKey>, num_sigs: u16) -> Option<TransactionAuth> {
pub fn from_p2wsh(privks: &[StacksPrivateKey], num_sigs: u16) -> Option<TransactionAuth> {
let mut pubks = vec![];
for privk in privks.iter() {
pubks.push(StacksPublicKey::from_private(privk));
Expand Down
4 changes: 2 additions & 2 deletions src/chainstate/stacks/block.rs
Original file line number Diff line number Diff line change
Expand Up @@ -440,7 +440,7 @@ impl StacksBlock {
}

/// verify no duplicate txids
pub fn validate_transactions_unique(txs: &Vec<StacksTransaction>) -> bool {
pub fn validate_transactions_unique(txs: &[StacksTransaction]) -> bool {
// no duplicates
let mut txids = HashMap::new();
for (i, tx) in txs.iter().enumerate() {
Expand Down Expand Up @@ -515,7 +515,7 @@ impl StacksBlock {
}

/// verify that a coinbase is present and is on-chain only, or is absent
pub fn validate_coinbase(txs: &Vec<StacksTransaction>, check_present: bool) -> bool {
pub fn validate_coinbase(txs: &[StacksTransaction], check_present: bool) -> bool {
let mut found_coinbase = false;
let mut coinbase_index = 0;
for (i, tx) in txs.iter().enumerate() {
Expand Down
4 changes: 2 additions & 2 deletions src/chainstate/stacks/db/accounts.rs
Original file line number Diff line number Diff line change
Expand Up @@ -555,7 +555,7 @@ impl StacksChainState {
pub fn insert_miner_payment_schedule<'a>(
tx: &mut DBTx<'a>,
block_reward: &MinerPaymentSchedule,
user_burns: &Vec<StagingUserBurnSupport>,
user_burns: &[StagingUserBurnSupport],
) -> Result<(), Error> {
assert!(block_reward.burnchain_commit_burn < i64::MAX as u64);
assert!(block_reward.burnchain_sortition_burn < i64::MAX as u64);
Expand Down Expand Up @@ -970,7 +970,7 @@ impl StacksChainState {
parent_block_epoch: StacksEpochId,
participant: &MinerPaymentSchedule,
miner: &MinerPaymentSchedule,
users: &Vec<MinerPaymentSchedule>,
users: &[MinerPaymentSchedule],
parent: &MinerPaymentSchedule,
poison_reporter_opt: Option<&StacksAddress>,
) -> (MinerReward, MinerReward) {
Expand Down
22 changes: 11 additions & 11 deletions src/chainstate/stacks/db/blocks.rs
Original file line number Diff line number Diff line change
Expand Up @@ -192,10 +192,10 @@ impl BlockEventDispatcher for DummyEventDispatcher {
&self,
_block: &StacksBlock,
_metadata: &StacksHeaderInfo,
_receipts: &Vec<StacksTransactionReceipt>,
_receipts: &[StacksTransactionReceipt],
_parent: &StacksBlockId,
_winner_txid: Txid,
_rewards: &Vec<MinerReward>,
_rewards: &[MinerReward],
_rewards_info: Option<&MinerRewardInfo>,
_parent_burn_block_hash: BurnchainHeaderHash,
_parent_burn_block_height: u32,
Expand Down Expand Up @@ -852,7 +852,7 @@ impl StacksChainState {
Ok(())
}

pub fn atomic_file_write(path: &str, bytes: &Vec<u8>) -> Result<(), Error> {
pub fn atomic_file_write(path: &str, bytes: &[u8]) -> Result<(), Error> {
StacksChainState::atomic_file_store(path, false, |ref mut fd| {
fd.write_all(bytes)
.map_err(|e| Error::DBError(db_error::IOError(e)))
Expand Down Expand Up @@ -2048,7 +2048,7 @@ impl StacksChainState {
tx: &mut DBTx<'a>,
consensus_hash: &ConsensusHash,
block_hash: &BlockHeaderHash,
burn_supports: &Vec<UserBurnSupportOp>,
burn_supports: &[UserBurnSupportOp],
) -> Result<(), Error> {
for burn_support in burn_supports.iter() {
assert!(burn_support.burn_fee < i64::MAX as u64);
Expand Down Expand Up @@ -3726,7 +3726,7 @@ impl StacksChainState {

fn extract_signed_microblocks(
parent_anchored_block_header: &StacksBlockHeader,
microblocks: &Vec<StacksMicroblock>,
microblocks: &[StacksMicroblock],
) -> Vec<StacksMicroblock> {
let mut signed_microblocks = vec![];
for microblock in microblocks.iter() {
Expand Down Expand Up @@ -3760,7 +3760,7 @@ impl StacksChainState {
pub fn validate_parent_microblock_stream(
parent_anchored_block_header: &StacksBlockHeader,
anchored_block_header: &StacksBlockHeader,
microblocks: &Vec<StacksMicroblock>,
microblocks: &[StacksMicroblock],
verify_signatures: bool,
) -> Option<(usize, Option<TransactionPayload>)> {
if anchored_block_header.is_first_mined() {
Expand All @@ -3781,7 +3781,7 @@ impl StacksChainState {
let signed_microblocks = if verify_signatures {
StacksChainState::extract_signed_microblocks(&parent_anchored_block_header, microblocks)
} else {
microblocks.clone()
microblocks.to_owned()
};

if signed_microblocks.len() == 0 {
Expand Down Expand Up @@ -4810,7 +4810,7 @@ impl StacksChainState {
/// Return the fees and burns.
pub fn process_microblocks_transactions(
clarity_tx: &mut ClarityTx,
microblocks: &Vec<StacksMicroblock>,
microblocks: &[StacksMicroblock],
ast_rules: ASTRules,
) -> Result<(u128, u128, Vec<StacksTransactionReceipt>), (Error, BlockHeaderHash)> {
let mut fees = 0u128;
Expand Down Expand Up @@ -5232,7 +5232,7 @@ impl StacksChainState {
pub fn process_matured_miner_rewards<'a, 'b>(
clarity_tx: &mut ClarityTx<'a, 'b>,
miner_share: &MinerReward,
users_share: &Vec<MinerReward>,
users_share: &[MinerReward],
parent_share: &MinerReward,
) -> Result<u128, Error> {
let mut coinbase_reward = miner_share.coinbase;
Expand Down Expand Up @@ -5305,7 +5305,7 @@ impl StacksChainState {
pub fn get_parent_matured_miner(
conn: &DBConn,
mainnet: bool,
latest_matured_miners: &Vec<MinerPaymentSchedule>,
latest_matured_miners: &[MinerPaymentSchedule],
) -> Result<MinerPaymentSchedule, Error> {
let parent_miner = if let Some(ref miner) = latest_matured_miners.first().as_ref() {
StacksChainState::get_scheduled_block_rewards_at_block(
Expand Down Expand Up @@ -5894,7 +5894,7 @@ impl StacksChainState {
microblocks: &Vec<StacksMicroblock>, // parent microblocks
burnchain_commit_burn: u64,
burnchain_sortition_burn: u64,
user_burns: &Vec<StagingUserBurnSupport>,
user_burns: &[StagingUserBurnSupport],
affirmation_weight: u64,
) -> Result<(StacksEpochReceipt, PreCommitClarityBlock<'a>), Error> {
debug!(
Expand Down
2 changes: 1 addition & 1 deletion src/chainstate/stacks/db/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2384,7 +2384,7 @@ impl StacksChainState {
new_burnchain_timestamp: u64,
microblock_tail_opt: Option<StacksMicroblockHeader>,
block_reward: &MinerPaymentSchedule,
user_burns: &Vec<StagingUserBurnSupport>,
user_burns: &[StagingUserBurnSupport],
mature_miner_payouts: Option<(MinerReward, Vec<MinerReward>, MinerReward, MinerRewardInfo)>, // (miner, [users], parent, matured rewards)
anchor_block_cost: &ExecutionCost,
anchor_block_size: u64,
Expand Down
Loading