Skip to content

Commit

Permalink
use references
Browse files Browse the repository at this point in the history
  • Loading branch information
Hanting Zhang committed Jan 10, 2024
1 parent f2b9fd4 commit e2dc2f9
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 21 deletions.
4 changes: 2 additions & 2 deletions benches/grumpkin_msm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ fn criterion_benchmark(c: &mut Criterion) {
})
});

let context = grumpkin_msm::bn256::init(points.clone());
let context = grumpkin_msm::bn256::init(&points);

group.bench_function(
format!("\"preallocate\" 2**{} points", bench_npow),
Expand Down Expand Up @@ -69,7 +69,7 @@ fn criterion_benchmark(c: &mut Criterion) {
})
});

let context = grumpkin_msm::bn256::init(points);
let context = grumpkin_msm::bn256::init(&points);

group.bench_function(
format!("preallocate 2**{} points", bench_npow),
Expand Down
4 changes: 2 additions & 2 deletions benches/pasta_msm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ fn criterion_benchmark(c: &mut Criterion) {
})
});

let context = grumpkin_msm::pasta::pallas::init(points.clone());
let context = grumpkin_msm::pasta::pallas::init(&points);

group.bench_function(
format!("\"preallocate\" 2**{} points", bench_npow),
Expand Down Expand Up @@ -69,7 +69,7 @@ fn criterion_benchmark(c: &mut Criterion) {
})
});

let context = grumpkin_msm::pasta::pallas::init(points);
let context = grumpkin_msm::pasta::pallas::init(&points);

group.bench_function(
format!("preallocate 2**{} points", bench_npow),
Expand Down
2 changes: 1 addition & 1 deletion examples/pasta_msm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ fn main() {
}

let native = naive_multiscalar_mul(&points, &scalars);
let context = grumpkin_msm::pasta::pallas::init(points);
let context = grumpkin_msm::pasta::pallas::init(&points);
let res = grumpkin_msm::pasta::pallas::with(&context, &scalars).to_affine();

assert_eq!(res, native);
Expand Down
16 changes: 8 additions & 8 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -105,17 +105,17 @@ macro_rules! impl_msm {
}

#[derive(Debug, Clone)]
pub enum MSMContext {
pub enum MSMContext<'a> {
CUDA(CudaMSMContext),
CPU(Vec<$affine>),
CPU(&'a [$affine]),
}

unsafe impl Send for MSMContext {}
unsafe impl<'a> Send for MSMContext<'a> {}

unsafe impl Sync for MSMContext {}
unsafe impl<'a> Sync for MSMContext<'a> {}

impl MSMContext {
pub fn new_cpu(points: Vec<$affine>) -> Self {
impl<'a> MSMContext<'a> {
pub fn new_cpu(points: &'a [$affine]) -> Self {
Self::CPU(points)
}

Expand All @@ -137,7 +137,7 @@ macro_rules! impl_msm {
}
}

pub fn points(&self) -> &Vec<$affine> {
pub fn points(&self) -> &[$affine] {
match self {
Self::CUDA(_) => {
panic!("cuda context; no host side points")
Expand Down Expand Up @@ -184,7 +184,7 @@ macro_rules! impl_msm {
$point::new_jacobian(ret.x, ret.y, ret.z).unwrap()
}

pub fn init(points: Vec<$affine>) -> MSMContext {
pub fn init(points: &[$affine]) -> MSMContext {
#[cfg(feature = "cuda")]
if unsafe { !CUDA_OFF && cuda_available() } {
extern "C" {
Expand Down
16 changes: 8 additions & 8 deletions src/pasta.rs
Original file line number Diff line number Diff line change
Expand Up @@ -87,17 +87,17 @@ macro_rules! impl_pasta {
}

#[derive(Debug, Clone)]
pub enum MSMContext {
pub enum MSMContext<'a> {
CUDA(CudaMSMContext),
CPU(Vec<$affine>),
CPU(&'a [$affine]),
}

unsafe impl Send for MSMContext {}
unsafe impl<'a> Send for MSMContext<'a> {}

unsafe impl Sync for MSMContext {}
unsafe impl<'a> Sync for MSMContext<'a> {}

impl MSMContext {
pub fn new_cpu(points: Vec<$affine>) -> Self {
impl<'a> MSMContext<'a> {
pub fn new_cpu(points: &'a [$affine]) -> Self {
Self::CPU(points)
}

Expand All @@ -119,7 +119,7 @@ macro_rules! impl_pasta {
}
}

pub fn points(&self) -> &Vec<$affine> {
pub fn points(&self) -> &[$affine] {
match self {
Self::CUDA(_) => {
panic!("cuda context; no host side points")
Expand Down Expand Up @@ -167,7 +167,7 @@ macro_rules! impl_pasta {
ret
}

pub fn init(points: Vec<$affine>) -> MSMContext {
pub fn init(points: &[$affine]) -> MSMContext {
#[cfg(feature = "cuda")]
if unsafe { !CUDA_OFF && cuda_available() } {
extern "C" {
Expand Down

0 comments on commit e2dc2f9

Please sign in to comment.