Skip to content

Commit

Permalink
TrustedLen
Browse files Browse the repository at this point in the history
  • Loading branch information
ijl committed Feb 28, 2023
1 parent 02910ee commit 15e42da
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 0 deletions.
4 changes: 4 additions & 0 deletions build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,10 @@ fn main() {
println!("cargo:rustc-cfg=feature=\"optimize\"");
}

if let Some(true) = version_check::supports_feature("trusted_len") {
println!("cargo:rustc-cfg=feature=\"trusted_len\"");
}

if env::var("ORJSON_DISABLE_WRITEEXT").is_ok() {
} else if env::var("ORJSON_ENABLE_WRITEEXT").is_ok()
|| env::var("CARGO_CFG_TARGET_OS").unwrap() == "macos"
Expand Down
8 changes: 8 additions & 0 deletions src/ffi/dict.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,4 +39,12 @@ impl Iterator for PyDictIter {
}
}
}

fn size_hint(&self) -> (usize, Option<usize>) {
let len = ffi!(Py_SIZE(self.dict_ptr)) as usize;
(len, Some(len))
}
}

#[cfg(feature = "trusted_len")]
unsafe impl std::iter::TrustedLen for PyDictIter {}
1 change: 1 addition & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
// SPDX-License-Identifier: (Apache-2.0 OR MIT)

#![cfg_attr(feature = "intrinsics", feature(core_intrinsics))]
#![cfg_attr(feature = "trusted_len", feature(trusted_len))]
#![cfg_attr(feature = "optimize", feature(optimize_attribute))]
#![allow(unused_unsafe)]
#![allow(non_camel_case_types)]
Expand Down

0 comments on commit 15e42da

Please sign in to comment.