Skip to content

Commit 0b43af8

Browse files
committed
Avoid using vec![]
1 parent 571735d commit 0b43af8

File tree

5 files changed

+26
-26
lines changed

5 files changed

+26
-26
lines changed

pineappl/src/packed_array.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,9 +28,9 @@ impl<T: Copy + Default + PartialEq> PackedArray<T> {
2828
#[must_use]
2929
pub const fn new(shape: Vec<usize>) -> Self {
3030
Self {
31-
entries: vec![],
32-
start_indices: vec![],
33-
lengths: vec![],
31+
entries: Vec::new(),
32+
start_indices: Vec::new(),
33+
lengths: Vec::new(),
3434
shape,
3535
}
3636
}

pineappl_capi/src/lib.rs

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -445,14 +445,14 @@ pub unsafe extern "C" fn pineappl_grid_convolve_with_one(
445445
let mut xfx = |id, x, q2| xfx(id, x, q2, state);
446446
let mut als = |q2| alphas(q2, state);
447447
let order_mask = if order_mask.is_null() {
448-
vec![]
448+
&[]
449449
} else {
450-
unsafe { slice::from_raw_parts(order_mask, grid.orders().len()) }.to_owned()
450+
unsafe { slice::from_raw_parts(order_mask, grid.orders().len()) }
451451
};
452452
let channel_mask = if channel_mask.is_null() {
453-
vec![]
453+
&[]
454454
} else {
455-
unsafe { slice::from_raw_parts(channel_mask, grid.channels().len()) }.to_vec()
455+
unsafe { slice::from_raw_parts(channel_mask, grid.channels().len()) }
456456
};
457457
let results = unsafe { slice::from_raw_parts_mut(results, grid.bin_info().bins()) };
458458
let mut convolution_cache = ConvolutionCache::new(
@@ -463,7 +463,7 @@ pub unsafe extern "C" fn pineappl_grid_convolve_with_one(
463463

464464
results.copy_from_slice(&grid.convolve(
465465
&mut convolution_cache,
466-
&order_mask,
466+
order_mask,
467467
&[],
468468
&channel_mask,
469469
&[(xi_ren, xi_fac, 1.0)],
@@ -511,14 +511,14 @@ pub unsafe extern "C" fn pineappl_grid_convolve_with_two(
511511
let mut xfx2 = |id, x, q2| xfx2(id, x, q2, state);
512512
let mut als = |q2| alphas(q2, state);
513513
let order_mask = if order_mask.is_null() {
514-
vec![]
514+
&[]
515515
} else {
516-
unsafe { slice::from_raw_parts(order_mask, grid.orders().len()) }.to_vec()
516+
unsafe { slice::from_raw_parts(order_mask, grid.orders().len()) }
517517
};
518518
let channel_mask = if channel_mask.is_null() {
519-
vec![]
519+
&[]
520520
} else {
521-
unsafe { slice::from_raw_parts(channel_mask, grid.channels().len()) }.to_vec()
521+
unsafe { slice::from_raw_parts(channel_mask, grid.channels().len()) }
522522
};
523523
let results = unsafe { slice::from_raw_parts_mut(results, grid.bin_info().bins()) };
524524
let mut convolution_cache = ConvolutionCache::new(
@@ -532,7 +532,7 @@ pub unsafe extern "C" fn pineappl_grid_convolve_with_two(
532532

533533
results.copy_from_slice(&grid.convolve(
534534
&mut convolution_cache,
535-
&order_mask,
535+
order_mask,
536536
&[],
537537
&channel_mask,
538538
&[(xi_ren, xi_fac, 1.0)],
@@ -1699,15 +1699,15 @@ pub unsafe extern "C" fn pineappl_grid_convolve(
16991699
let grid = unsafe { &*grid };
17001700

17011701
let order_mask = if order_mask.is_null() {
1702-
vec![]
1702+
&[]
17031703
} else {
1704-
unsafe { slice::from_raw_parts(order_mask, grid.orders().len()) }.to_owned()
1704+
unsafe { slice::from_raw_parts(order_mask, grid.orders().len()) }
17051705
};
17061706

17071707
let channel_mask = if channel_mask.is_null() {
1708-
vec![]
1708+
&[]
17091709
} else {
1710-
unsafe { slice::from_raw_parts(channel_mask, grid.channels().len()) }.to_vec()
1710+
unsafe { slice::from_raw_parts(channel_mask, grid.channels().len()) }
17111711
};
17121712

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

17471747
results.copy_from_slice(&grid.convolve(
17481748
&mut convolution_cache,
1749-
&order_mask,
1749+
order_mask,
17501750
bin_indices,
1751-
&channel_mask,
1751+
channel_mask,
17521752
mu_scales,
17531753
));
17541754
}

pineappl_cli/src/import.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,7 @@ fn convert_fastnlo(
133133
fn convert_fktable(input: &Path) -> Result<(&'static str, Grid, Vec<f64>, usize)> {
134134
let fktable = fktable::convert_fktable(input)?;
135135

136-
Ok(("fktable", fktable, vec![], 1))
136+
Ok(("fktable", fktable, Vec::new(), 1))
137137
}
138138

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

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

201201
/// Converts APPLgrid/fastNLO/FastKernel files to PineAPPL grids.

pineappl_cli/src/plot.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -379,7 +379,7 @@ impl Subcommand for Opts {
379379
.collect();
380380

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

695-
let mut x1_vals = vec![];
696-
let mut x2_vals = vec![];
697-
let mut vals = vec![];
695+
let mut x1_vals = Vec::new();
696+
let mut x2_vals = Vec::new();
697+
let mut vals = Vec::new();
698698

699699
for (((ix1, ix2), &one), &two) in res1.indexed_iter().zip(res2.iter()) {
700700
if one == 0.0 {

pineappl_cli/src/pull.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -206,7 +206,7 @@ impl Subcommand for Opts {
206206
};
207207

208208
let mut pull_tuples = if self.limit == 0 {
209-
vec![]
209+
Vec::new()
210210
} else {
211211
let channel_results1 = channel_results(
212212
self.conv_funs1.members[self.pull_from],

0 commit comments

Comments
 (0)