From 7045fe7e2a308f2654aa3fea238b831a27172d88 Mon Sep 17 00:00:00 2001 From: Jan Verbeek Date: Fri, 29 Jan 2021 18:48:21 +0100 Subject: [PATCH] Use borrowed instead of owned string arguments This seems to speed it up about 10% because it avoids copying the strings. --- src/lib.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/lib.rs b/src/lib.rs index 1fd8ef6..cfd64a9 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -15,9 +15,9 @@ fn init_mod(_py: Python, m: &PyModule) -> PyResult<()> { // We fill this module with everything we want to make visible from Python. #[pyfn(m, "parse")] - fn parse(_py: Python, str_datetime: String, fmt: String) -> PyResult<&PyDateTime> { + fn parse<'a>(_py: Python<'a>, str_datetime: &str, fmt: &str) -> PyResult<&'a PyDateTime> { // Call chrono and ask it to parse the datetime for us - let chrono_dt = Utc.datetime_from_str(str_datetime.as_str(), fmt.as_str()); + let chrono_dt = Utc.datetime_from_str(str_datetime, fmt); // In case chrono couldn't parse a datetime, raise a ValueError with chrono's error message. // Because there are no exceptions in Rust, we return a PyValueError instance here.