Skip to content
This repository has been archived by the owner on Jan 12, 2024. It is now read-only.

remove unnecessary heap allocation #1156

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
6 changes: 2 additions & 4 deletions src/Simulation/qdk_sim_rs/benches/c_api_benchmark.rs
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,7 @@ fn with_test_suite<T: criterion::measurement::Measurement>(
fn ideal(c: &mut Criterion) {
let mut sim_id: usize = 0;
unsafe {
let repr = CString::new("mixed").unwrap();
let _err = c_api::init(3, repr.as_ptr(), &mut sim_id);
let _err = c_api::init(3, "mixed\0".as_ptr() as _, &mut sim_id);
}
let mut group = c.benchmark_group("ideal");
with_test_suite(sim_id, &mut group);
Expand All @@ -63,8 +62,7 @@ fn ideal(c: &mut Criterion) {
fn noisy(c: &mut Criterion) {
let mut sim_id: usize = 0;
unsafe {
let repr = CString::new("mixed").unwrap();
let _err = c_api::init(3, repr.as_ptr(), &mut sim_id);
let _err = c_api::init(3, "mixed\0".as_ptr() as _, &mut sim_id);
}
// NB: The C API is not in general safe.
unsafe {
Expand Down
9 changes: 3 additions & 6 deletions src/Simulation/qdk_sim_rs/src/c_api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -581,8 +581,7 @@ mod tests {
fn ry_runs_without_error_or_panic() -> Result<(), (String, i64)> {
unsafe {
let mut sim_id: usize = 0;
let mixed = CString::new("mixed").unwrap();
as_result(c_api::init(3, mixed.as_ptr(), &mut sim_id))?;
as_result(c_api::init(3, "mixed\0".as_ptr() as _, &mut sim_id))?;
as_result(c_api::ry(sim_id, 1.234, 1))?;
as_result(c_api::destroy(sim_id))?;
Ok(())
Expand All @@ -593,10 +592,8 @@ mod tests {
fn teleport() -> Result<(), (String, i64)> {
unsafe {
let mut sim_id: usize = 0;
let mixed = CString::new("mixed").unwrap();
let ideal = CString::new("ideal").unwrap();
as_result(c_api::init(3, mixed.as_ptr(), &mut sim_id))?;
as_result(c_api::set_noise_model_by_name(sim_id, ideal.as_ptr()))?;
as_result(c_api::init(3, "mixed\0".as_ptr() as _, &mut sim_id))?;
as_result(c_api::set_noise_model_by_name(sim_id, "ideal\0".as_ptr() as _))?;

let idx_msg = 0;
let idx_here = 1;
Expand Down