remove unnecessary heap allocation (#30272)

This commit is contained in:
XXIV 2023-09-01 07:44:24 +03:00 committed by GitHub
parent e6558e35d2
commit 6eb3e16578
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -41,7 +41,7 @@ impl LocalCPrefValue {
match v { match v {
PrefValue::Float(v) => LocalCPrefValue::Float(*v), PrefValue::Float(v) => LocalCPrefValue::Float(*v),
PrefValue::Int(v) => LocalCPrefValue::Int(*v), PrefValue::Int(v) => LocalCPrefValue::Int(*v),
PrefValue::Str(v) => LocalCPrefValue::Str(CString::new(v.clone()).unwrap()), PrefValue::Str(v) => LocalCPrefValue::Str(CString::new(v.as_bytes()).unwrap()),
PrefValue::Bool(v) => LocalCPrefValue::Bool(*v), PrefValue::Bool(v) => LocalCPrefValue::Bool(*v),
PrefValue::Missing => LocalCPrefValue::Missing, PrefValue::Missing => LocalCPrefValue::Missing,
} }
@ -203,7 +203,7 @@ pub extern "C" fn get_prefs() -> CPrefList {
.into_iter() .into_iter()
.map(|(key, (value, is_default))| { .map(|(key, (value, is_default))| {
let l = Box::new(LocalCPref { let l = Box::new(LocalCPref {
key: CString::new(key.clone()).unwrap(), key: CString::new(key.as_bytes()).unwrap(),
value: LocalCPrefValue::new(&value), value: LocalCPrefValue::new(&value),
is_default: is_default, is_default: is_default,
}); });