Skip to content

Commit

Permalink
Avoid using vec![]
Browse files Browse the repository at this point in the history
  • Loading branch information
cschwan committed Dec 17, 2024
1 parent 571735d commit 0b43af8
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 26 deletions.
6 changes: 3 additions & 3 deletions pineappl/src/packed_array.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,9 @@ impl<T: Copy + Default + PartialEq> PackedArray<T> {
#[must_use]
pub const fn new(shape: Vec<usize>) -> Self {
Self {
entries: vec![],
start_indices: vec![],
lengths: vec![],
entries: Vec::new(),
start_indices: Vec::new(),
lengths: Vec::new(),
shape,
}
}
Expand Down
32 changes: 16 additions & 16 deletions pineappl_capi/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -445,14 +445,14 @@ pub unsafe extern "C" fn pineappl_grid_convolve_with_one(
let mut xfx = |id, x, q2| xfx(id, x, q2, state);
let mut als = |q2| alphas(q2, state);
let order_mask = if order_mask.is_null() {
vec![]
&[]
} else {
unsafe { slice::from_raw_parts(order_mask, grid.orders().len()) }.to_owned()
unsafe { slice::from_raw_parts(order_mask, grid.orders().len()) }
};
let channel_mask = if channel_mask.is_null() {
vec![]
&[]
} else {
unsafe { slice::from_raw_parts(channel_mask, grid.channels().len()) }.to_vec()
unsafe { slice::from_raw_parts(channel_mask, grid.channels().len()) }
};
let results = unsafe { slice::from_raw_parts_mut(results, grid.bin_info().bins()) };
let mut convolution_cache = ConvolutionCache::new(
Expand All @@ -463,7 +463,7 @@ pub unsafe extern "C" fn pineappl_grid_convolve_with_one(

results.copy_from_slice(&grid.convolve(
&mut convolution_cache,
&order_mask,
order_mask,
&[],
&channel_mask,
&[(xi_ren, xi_fac, 1.0)],
Expand Down Expand Up @@ -511,14 +511,14 @@ pub unsafe extern "C" fn pineappl_grid_convolve_with_two(
let mut xfx2 = |id, x, q2| xfx2(id, x, q2, state);
let mut als = |q2| alphas(q2, state);
let order_mask = if order_mask.is_null() {
vec![]
&[]
} else {
unsafe { slice::from_raw_parts(order_mask, grid.orders().len()) }.to_vec()
unsafe { slice::from_raw_parts(order_mask, grid.orders().len()) }
};
let channel_mask = if channel_mask.is_null() {
vec![]
&[]
} else {
unsafe { slice::from_raw_parts(channel_mask, grid.channels().len()) }.to_vec()
unsafe { slice::from_raw_parts(channel_mask, grid.channels().len()) }
};
let results = unsafe { slice::from_raw_parts_mut(results, grid.bin_info().bins()) };
let mut convolution_cache = ConvolutionCache::new(
Expand All @@ -532,7 +532,7 @@ pub unsafe extern "C" fn pineappl_grid_convolve_with_two(

results.copy_from_slice(&grid.convolve(
&mut convolution_cache,
&order_mask,
order_mask,
&[],
&channel_mask,
&[(xi_ren, xi_fac, 1.0)],
Expand Down Expand Up @@ -1699,15 +1699,15 @@ pub unsafe extern "C" fn pineappl_grid_convolve(
let grid = unsafe { &*grid };

let order_mask = if order_mask.is_null() {
vec![]
&[]
} else {
unsafe { slice::from_raw_parts(order_mask, grid.orders().len()) }.to_owned()
unsafe { slice::from_raw_parts(order_mask, grid.orders().len()) }
};

let channel_mask = if channel_mask.is_null() {
vec![]
&[]
} else {
unsafe { slice::from_raw_parts(channel_mask, grid.channels().len()) }.to_vec()
unsafe { slice::from_raw_parts(channel_mask, grid.channels().len()) }
};

let bin_indices = if bin_indices.is_null() {
Expand Down Expand Up @@ -1746,9 +1746,9 @@ pub unsafe extern "C" fn pineappl_grid_convolve(

results.copy_from_slice(&grid.convolve(
&mut convolution_cache,
&order_mask,
order_mask,
bin_indices,
&channel_mask,
channel_mask,
mu_scales,
));
}
4 changes: 2 additions & 2 deletions pineappl_cli/src/import.rs
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ fn convert_fastnlo(
fn convert_fktable(input: &Path) -> Result<(&'static str, Grid, Vec<f64>, usize)> {
let fktable = fktable::convert_fktable(input)?;

Ok(("fktable", fktable, vec![], 1))
Ok(("fktable", fktable, Vec::new(), 1))
}

#[cfg(not(feature = "fktable"))]
Expand Down Expand Up @@ -195,7 +195,7 @@ fn fnlo_mu_possible_values() -> Vec<&'static str> {

#[cfg(not(feature = "fastnlo"))]
const fn fnlo_mu_possible_values() -> Vec<&'static str> {
vec![]
Vec::new()
}

/// Converts APPLgrid/fastNLO/FastKernel files to PineAPPL grids.
Expand Down
8 changes: 4 additions & 4 deletions pineappl_cli/src/plot.rs
Original file line number Diff line number Diff line change
Expand Up @@ -379,7 +379,7 @@ impl Subcommand for Opts {
.collect();

let channels = if matches!(mode, ConvoluteMode::Asymmetry) {
vec![]
Vec::new()
} else {
let mut channels: Vec<_> = (0..grid.channels().len())
.map(|channel| {
Expand Down Expand Up @@ -692,9 +692,9 @@ metadata = {{
// TODO: convert this into an error
.unwrap();

let mut x1_vals = vec![];
let mut x2_vals = vec![];
let mut vals = vec![];
let mut x1_vals = Vec::new();
let mut x2_vals = Vec::new();
let mut vals = Vec::new();

for (((ix1, ix2), &one), &two) in res1.indexed_iter().zip(res2.iter()) {
if one == 0.0 {
Expand Down
2 changes: 1 addition & 1 deletion pineappl_cli/src/pull.rs
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,7 @@ impl Subcommand for Opts {
};

let mut pull_tuples = if self.limit == 0 {
vec![]
Vec::new()
} else {
let channel_results1 = channel_results(
self.conv_funs1.members[self.pull_from],
Expand Down

0 comments on commit 0b43af8

Please sign in to comment.