diff options
| author | David Lönnhager <david.l@mullvad.net> | 2022-03-22 09:58:05 +0100 |
|---|---|---|
| committer | David Lönnhager <david.l@mullvad.net> | 2022-03-23 17:02:05 +0100 |
| commit | e4ebfaa1131701466bcea1643248d967cc2d40cf (patch) | |
| tree | 4bbc9504223395f6a6938bf0735d756317ed9ce0 | |
| parent | d91e14f3a53dc26c0ba93b1c9cd75eaf3928d875 (diff) | |
| download | mullvadvpn-e4ebfaa1131701466bcea1643248d967cc2d40cf.tar.xz mullvadvpn-e4ebfaa1131701466bcea1643248d967cc2d40cf.zip | |
Fix pointless copying
| -rw-r--r-- | mullvad-daemon/src/migrations/account_history.rs | 13 |
1 files changed, 7 insertions, 6 deletions
diff --git a/mullvad-daemon/src/migrations/account_history.rs b/mullvad-daemon/src/migrations/account_history.rs index bdd955468e..5400f04e33 100644 --- a/mullvad-daemon/src/migrations/account_history.rs +++ b/mullvad-daemon/src/migrations/account_history.rs @@ -106,12 +106,13 @@ fn try_format_v2(bytes: &[u8]) -> Option<(AccountToken, serde_json::Value)> { pub wireguard: serde_json::Value, } serde_json::from_slice(bytes) - .map(|entries: Vec<AccountEntry>| { + .ok() + .and_then(|entries: Vec<AccountEntry>| { entries - .first() - .map(|entry| (entry.account.clone(), entry.wireguard.clone())) + .into_iter() + .next() + .map(|entry| (entry.account, entry.wireguard)) }) - .unwrap_or(None) } fn try_format_v1(bytes: &[u8]) -> Option<AccountToken> { @@ -120,8 +121,8 @@ fn try_format_v1(bytes: &[u8]) -> Option<AccountToken> { accounts: Vec<AccountToken>, } serde_json::from_slice(bytes) - .map(|old_format: OldFormat| old_format.accounts.first().cloned()) - .unwrap_or(None) + .ok() + .and_then(|old_format: OldFormat| old_format.accounts.into_iter().next()) } #[cfg(test)] |
