Skip to content

Commit

Permalink
Merge pull request #1826 from davidhewitt/pysequence-tidy
Browse files Browse the repository at this point in the history
sequence: tidy up implementation
  • Loading branch information
davidhewitt committed Aug 24, 2021
2 parents 50cd4c6 + 7ff7c76 commit 688823f
Showing 1 changed file with 11 additions and 26 deletions.
37 changes: 11 additions & 26 deletions src/types/sequence.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,13 +40,8 @@ impl PySequence {
#[inline]
pub fn concat(&self, other: &PySequence) -> PyResult<&PySequence> {
unsafe {
let ptr = self
.py()
.from_owned_ptr_or_err::<PyAny>(ffi::PySequence_Concat(
self.as_ptr(),
other.as_ptr(),
))?;
Ok(&*(ptr as *const PyAny as *const PySequence))
self.py()
.from_owned_ptr_or_err(ffi::PySequence_Concat(self.as_ptr(), other.as_ptr()))
}
}

Expand All @@ -56,13 +51,10 @@ impl PySequence {
#[inline]
pub fn repeat(&self, count: usize) -> PyResult<&PySequence> {
unsafe {
let ptr = self
.py()
.from_owned_ptr_or_err::<PyAny>(ffi::PySequence_Repeat(
self.as_ptr(),
get_ssize_index(count),
))?;
Ok(&*(ptr as *const PyAny as *const PySequence))
self.py().from_owned_ptr_or_err(ffi::PySequence_Repeat(
self.as_ptr(),
get_ssize_index(count),
))
}
}

Expand All @@ -76,13 +68,8 @@ impl PySequence {
#[inline]
pub fn in_place_concat(&self, other: &PySequence) -> PyResult<&PySequence> {
unsafe {
let ptr = self
.py()
.from_owned_ptr_or_err::<PyAny>(ffi::PySequence_InPlaceConcat(
self.as_ptr(),
other.as_ptr(),
))?;
Ok(&*(ptr as *const PyAny as *const PySequence))
self.py()
.from_owned_ptr_or_err(ffi::PySequence_InPlaceConcat(self.as_ptr(), other.as_ptr()))
}
}

Expand All @@ -96,13 +83,11 @@ impl PySequence {
#[inline]
pub fn in_place_repeat(&self, count: usize) -> PyResult<&PySequence> {
unsafe {
let ptr = self
.py()
.from_owned_ptr_or_err::<PyAny>(ffi::PySequence_InPlaceRepeat(
self.py()
.from_owned_ptr_or_err(ffi::PySequence_InPlaceRepeat(
self.as_ptr(),
get_ssize_index(count),
))?;
Ok(&*(ptr as *const PyAny as *const PySequence))
))
}
}

Expand Down

0 comments on commit 688823f

Please sign in to comment.