Skip to content

Commit 68a74ff

Browse files
committed
Add nightly-optimizations feature
1 parent 45cb26d commit 68a74ff

File tree

2 files changed

+21
-0
lines changed

2 files changed

+21
-0
lines changed

Cargo.toml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,10 @@ python3 = []
4848
# so that the module can also be used with statically linked python interpreters.
4949
extension-module = []
5050

51+
# Use this feature to enable optimizations only possible on nightly Rust.
52+
# (Dependent on specialization.)
53+
nightly-optimizations = []
54+
5155
# The stable cpython abi as defined in PEP 384. Currently broken with
5256
# many compilation errors. Pull Requests working towards fixing that
5357
# are welcome.

src/types/sequence.rs

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
// Copyright (c) 2017-present PyO3 Project and Contributors
22

3+
#[cfg(nightly_optimizations)]
34
use crate::buffer;
45
use crate::err::{self, PyDowncastError, PyErr, PyResult};
56
use crate::exceptions;
@@ -265,13 +266,22 @@ macro_rules! array_impls {
265266
where
266267
T: Copy + Default + FromPyObject<'a>,
267268
{
269+
#[cfg(not(nightly_optimizations))]
270+
fn extract(obj: &'a PyAny) -> PyResult<Self> {
271+
let mut array = [T::default(); $N];
272+
extract_sequence_into_slice(obj, &mut array)?;
273+
Ok(array)
274+
}
275+
276+
#[cfg(nightly_optimizations)]
268277
default fn extract(obj: &'a PyAny) -> PyResult<Self> {
269278
let mut array = [T::default(); $N];
270279
extract_sequence_into_slice(obj, &mut array)?;
271280
Ok(array)
272281
}
273282
}
274283

284+
#[cfg(nightly_optimizations)]
275285
impl<'source, T> FromPyObject<'source> for [T; $N]
276286
where
277287
for<'a> T: Copy + Default + FromPyObject<'a> + buffer::Element,
@@ -304,11 +314,18 @@ impl<'a, T> FromPyObject<'a> for Vec<T>
304314
where
305315
T: FromPyObject<'a>,
306316
{
317+
#[cfg(not(nightly_optimizations))]
318+
fn extract(obj: &'a PyAny) -> PyResult<Self> {
319+
extract_sequence(obj)
320+
}
321+
322+
#[cfg(nightly_optimizations)]
307323
default fn extract(obj: &'a PyAny) -> PyResult<Self> {
308324
extract_sequence(obj)
309325
}
310326
}
311327

328+
#[cfg(nightly_optimizations)]
312329
impl<'source, T> FromPyObject<'source> for Vec<T>
313330
where
314331
for<'a> T: FromPyObject<'a> + buffer::Element + Copy,

0 commit comments

Comments
 (0)