Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

sequence: tidy up implementation #1826

Merged
merged 1 commit into from
Aug 24, 2021
Merged
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
37 changes: 11 additions & 26 deletions src/types/sequence.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,13 +39,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 @@ -55,13 +50,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 @@ -75,13 +67,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 @@ -95,13 +82,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