Skip to content

Commit

Permalink
Improve performance of CircuitData::__getitem__ (#11842)
Browse files Browse the repository at this point in the history
The order of the variants in `SliceOrInt` determines which is tried
first by the `FromPyObject` derivation.  `Int` is more common in like
99.9+% of cases, so wants to be first.
  • Loading branch information
jakelishman committed Feb 20, 2024
1 parent 060cb70 commit 6a8bdb7
Showing 1 changed file with 3 additions and 1 deletion.
4 changes: 3 additions & 1 deletion crates/accelerate/src/quantum_circuit/circuit_data.rs
Original file line number Diff line number Diff line change
Expand Up @@ -157,8 +157,10 @@ pub struct CircuitData {
/// that may be either an index or a slice.
#[derive(FromPyObject)]
pub enum SliceOrInt<'a> {
Slice(&'a PySlice),
// The order here defines the order the variants are tried in the `FromPyObject` derivation.
// `Int` is _much_ more common, so that should be first.
Int(isize),
Slice(&'a PySlice),
}

#[pymethods]
Expand Down

0 comments on commit 6a8bdb7

Please sign in to comment.