Skip to content

Commit

Permalink
Update to android_system_properties v0.1.5
Browse files Browse the repository at this point in the history
The new release makes `AndroidSystemProperties` send + sync, so the
initialization can be cached. This makes the stress test execute in

```text
0m00.61s real     0m04.00s user     0m00.02s system
```

Before it was

```text
1m37.25s real     1m06.81s user     0m57.95s system
```

I.e. it's now 9786 % faster. :)
  • Loading branch information
Kijewski committed Aug 30, 2022
1 parent 41c9d38 commit c7fa181
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 5 deletions.
5 changes: 3 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
[package]
name = "iana-time-zone"
description = "get the IANA time zone for the current system"
version = "0.1.46"
version = "0.1.47"
authors = ["Andrew Straw <strawman@astraw.com>"]
repository = "https://github.com/strawlab/iana-time-zone"
license = "MIT OR Apache-2.0"
Expand All @@ -15,7 +15,8 @@ edition = "2018"
fallback = []

[target.'cfg(target_os = "android")'.dependencies]
android_system_properties = "0.1.4"
android_system_properties = "0.1.5"
once_cell = "1.13.1"

[target.'cfg(any(target_os = "macos", target_os = "ios"))'.dependencies]
core-foundation-sys = "0.8.3"
Expand Down
10 changes: 7 additions & 3 deletions src/tz_android.rs
Original file line number Diff line number Diff line change
@@ -1,12 +1,16 @@
use std::ffi::CStr;

use android_system_properties::AndroidSystemProperties;
use once_cell::sync::OnceCell;

// From https://android.googlesource.com/platform/ndk/+/android-4.2.2_r1.2/docs/system/libc/OVERVIEW.html
// The system property named 'persist.sys.timezone' contains the name of the current timezone.

const TIMEZONE_PROP_KEY: &str = "persist.sys.timezone";
static PROPERTIES: OnceCell<AndroidSystemProperties> = OnceCell::new();

pub(crate) fn get_timezone_inner() -> Result<String, crate::GetTimezoneError> {
AndroidSystemProperties::new()
.get(TIMEZONE_PROP_KEY)
PROPERTIES
.get_or_init(AndroidSystemProperties::new)
.get_from_cstr(unsafe { CStr::from_bytes_with_nul_unchecked(b"persist.sys.timezone\0") })
.ok_or(crate::GetTimezoneError::OsError)
}

0 comments on commit c7fa181

Please sign in to comment.