Skip to content

Commit

Permalink
restore pystring_ascii_new fast path, using new PyO3 instead
Browse files Browse the repository at this point in the history
  • Loading branch information
davidhewitt committed Dec 3, 2024
1 parent 06aa3a5 commit 01a0e54
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 14 deletions.
4 changes: 4 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -31,3 +31,7 @@ debug = true
[workspace.dependencies]
pyo3 = { version = "0.23" }
pyo3-build-config = { version = "0.23" }

[patch.crates-io]
pyo3 = { git = "https://github.com/davidhewitt/pyo3", branch = "config-file-env-var" }
pyo3-build-config = { git = "https://github.com/davidhewitt/pyo3", branch = "config-file-env-var" }
16 changes: 2 additions & 14 deletions crates/jiter/src/py_string_cache.rs
Original file line number Diff line number Diff line change
Expand Up @@ -208,13 +208,7 @@ pub fn pystring_fast_new<'py>(py: Python<'py>, s: &str, ascii_only: bool) -> Bou

/// Faster creation of PyString from an ASCII string, inspired by
/// https://github.com/ijl/orjson/blob/3.10.0/src/str/create.rs#L41
#[cfg(all(
any(
all(target_arch = "x86_64", target_os = "linux"),
all(target_arch = "aarch64", target_os = "macos"),
),
not(any(PyPy, GraalPy))
))]
#[cfg(not(any(PyPy, GraalPy)))]
unsafe fn pystring_ascii_new<'py>(py: Python<'py>, s: &str) -> Bound<'py, PyString> {
// disabled on everything except tier-1 platforms because of a crash in the built wheels from CI,
// see https://github.com/pydantic/jiter/pull/175
Expand All @@ -229,13 +223,7 @@ unsafe fn pystring_ascii_new<'py>(py: Python<'py>, s: &str) -> Bound<'py, PyStri
}

// unoptimized version (albeit not that much slower) on other platforms
#[cfg(not(all(
any(
all(target_arch = "x86_64", target_os = "linux"),
all(target_arch = "aarch64", target_os = "macos"),
),
not(any(PyPy, GraalPy)),
)))]
#[cfg(any(PyPy, GraalPy))]
unsafe fn pystring_ascii_new<'py>(py: Python<'py>, s: &str) -> Bound<'py, PyString> {
PyString::new(py, s)
}

0 comments on commit 01a0e54

Please sign in to comment.