Skip to content

Commit 5a4df5a

Browse files
committed
Inline the layout-related methods as these basically change types and could benefit from cold branch removal.
1 parent 93a3aaf commit 5a4df5a

File tree

1 file changed

+4
-0
lines changed

1 file changed

+4
-0
lines changed

src/array.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -151,6 +151,7 @@ impl<'py, T: Element, D: Dimension> FromPyObject<'py> for &'py PyArray<T, D> {
151151

152152
impl<T, D> PyArray<T, D> {
153153
/// Returns a raw pointer to the underlying [`PyArrayObject`][npyffi::PyArrayObject].
154+
#[inline]
154155
pub fn as_array_ptr(&self) -> *mut npyffi::PyArrayObject {
155156
self.as_ptr() as _
156157
}
@@ -282,6 +283,7 @@ impl<T, D> PyArray<T, D> {
282283
///
283284
/// [ndarray-ndim]: https://numpy.org/doc/stable/reference/generated/numpy.ndarray.ndim.html
284285
/// [PyArray_NDIM]: https://numpy.org/doc/stable/reference/c-api/array.html#c.PyArray_NDIM
286+
#[inline]
285287
pub fn ndim(&self) -> usize {
286288
unsafe { (*self.as_array_ptr()).nd as usize }
287289
}
@@ -304,6 +306,7 @@ impl<T, D> PyArray<T, D> {
304306
/// ```
305307
/// [ndarray-strides]: https://numpy.org/doc/stable/reference/generated/numpy.ndarray.strides.html
306308
/// [PyArray_STRIDES]: https://numpy.org/doc/stable/reference/c-api/array.html#c.PyArray_STRIDES
309+
#[inline]
307310
pub fn strides(&self) -> &[isize] {
308311
let n = self.ndim();
309312
if n == 0 {
@@ -336,6 +339,7 @@ impl<T, D> PyArray<T, D> {
336339
///
337340
/// [ndarray-shape]: https://numpy.org/doc/stable/reference/generated/numpy.ndarray.shape.html
338341
/// [PyArray_DIMS]: https://numpy.org/doc/stable/reference/c-api/array.html#c.PyArray_DIMS
342+
#[inline]
339343
pub fn shape(&self) -> &[usize] {
340344
let n = self.ndim();
341345
if n == 0 {

0 commit comments

Comments
 (0)