-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Update to android_system_properties v0.1.5
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
Showing
2 changed files
with
10 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | ||
} |