Skip to content

Commit

Permalink
Accept Option<&str> instead of &Option<String>, etc
Browse files Browse the repository at this point in the history
In a few places, this removes unnecessary object copies.

Accept a wider range of input types, and more idiomatic input types
in a few functions. This affects code added in the gates-in-rust PR.

The great majority of the changes here were obsoleted by Qiskit#12594.
The original commit has been cherry picked on top of main.
  • Loading branch information
jlapeyre committed Jun 25, 2024
1 parent 1ed5951 commit e75c9c3
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 10 deletions.
8 changes: 1 addition & 7 deletions crates/circuit/src/circuit_data.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1104,13 +1104,7 @@ impl CircuitData {
Ok(PySet::new_bound(py, self.param_table.uuid_map.values())?.unbind())
}

pub fn pop_param(
&mut self,
py: Python,
uuid: u128,
name: String,
default: PyObject,
) -> PyObject {
pub fn pop_param(&mut self, py: Python, uuid: u128, name: &str, default: PyObject) -> PyObject {
match self.param_table.pop(uuid, name) {
Some(res) => res.into_py(py),
None => default.clone_ref(py),
Expand Down
2 changes: 1 addition & 1 deletion crates/circuit/src/circuit_instruction.rs
Original file line number Diff line number Diff line change
Expand Up @@ -778,7 +778,7 @@ pub(crate) fn operation_type_and_data_to_py(
let kwargs = [
("label", label.to_object(py)),
("unit", unit.to_object(py)),
("duration", duration.to_object(py)),
("duration", duration.as_ref().to_object(py)),
]
.into_py_dict_bound(py);
let mut out = gate_class.call_bound(py, args, Some(&kwargs))?;
Expand Down
4 changes: 2 additions & 2 deletions crates/circuit/src/parameter_table.rs
Original file line number Diff line number Diff line change
Expand Up @@ -153,8 +153,8 @@ impl ParamTable {
self.uuid_map.clear();
}

pub fn pop(&mut self, key: u128, name: String) -> Option<ParamEntry> {
self.names.remove(&name);
pub fn pop(&mut self, key: u128, name: &str) -> Option<ParamEntry> {
self.names.remove(name);
self.uuid_map.remove(&key);
self.table.remove(&key)
}
Expand Down

0 comments on commit e75c9c3

Please sign in to comment.