1
0
Fork 1
Spiegel von https://github.com/dani-garcia/vaultwarden.git synchronisiert 2024-11-26 05:50:29 +01:00

Changed uppercase deserializer to avoid a clone.

Dieser Commit ist enthalten in:
Daniel García 2019-03-18 22:02:37 +01:00
Ursprung 084bc2aee3
Commit 4689ed7b30
Es konnte kein GPG-Schlüssel zu dieser Signatur gefunden werden
GPG-Schlüssel-ID: FC8A7D14C3CD543A

Datei anzeigen

@ -218,7 +218,7 @@ impl<'de> Visitor<'de> for UpCaseVisitor {
let mut result_map = JsonMap::new(); let mut result_map = JsonMap::new();
while let Some((key, value)) = map.next_entry()? { while let Some((key, value)) = map.next_entry()? {
result_map.insert(upcase_first(key), upcase_value(&value)); result_map.insert(upcase_first(key), upcase_value(value));
} }
Ok(Value::Object(result_map)) Ok(Value::Object(result_map))
@ -231,32 +231,32 @@ impl<'de> Visitor<'de> for UpCaseVisitor {
let mut result_seq = Vec::<Value>::new(); let mut result_seq = Vec::<Value>::new();
while let Some(value) = seq.next_element()? { while let Some(value) = seq.next_element()? {
result_seq.push(upcase_value(&value)); result_seq.push(upcase_value(value));
} }
Ok(Value::Array(result_seq)) Ok(Value::Array(result_seq))
} }
} }
fn upcase_value(value: &Value) -> Value { fn upcase_value(value: Value) -> Value {
if let Some(map) = value.as_object() { if let Value::Object(map) = value {
let mut new_value = json!({}); let mut new_value = json!({});
for (key, val) in map { for (key, val) in map.into_iter() {
let processed_key = _process_key(key); let processed_key = _process_key(&key);
new_value[processed_key] = upcase_value(val); new_value[processed_key] = upcase_value(val);
} }
new_value new_value
} else if let Some(array) = value.as_array() { } else if let Value::Array(array) = value {
// Initialize array with null values // Initialize array with null values
let mut new_value = json!(vec![Value::Null; array.len()]); let mut new_value = json!(vec![Value::Null; array.len()]);
for (index, val) in array.iter().enumerate() { for (index, val) in array.into_iter().enumerate() {
new_value[index] = upcase_value(val); new_value[index] = upcase_value(val);
} }
new_value new_value
} else { } else {
value.clone() value
} }
} }