diff options
author | Jason A. Donenfeld <Jason@zx2c4.com> | 2019-02-04 21:30:33 +0100 |
---|---|---|
committer | Jason A. Donenfeld <Jason@zx2c4.com> | 2019-02-06 01:52:31 +0100 |
commit | a26d620f11656532df14ce566a701d5c5cbb850e (patch) | |
tree | 3eaa298d2ead4533621127950430d3cece339783 /WireGuard/WireGuard/Tunnel/TunnelsManager.swift | |
parent | Project: Remove OS name from appex file name (diff) | |
download | wireguard-apple-a26d620f11656532df14ce566a701d5c5cbb850e.tar.xz wireguard-apple-a26d620f11656532df14ce566a701d5c5cbb850e.zip |
TunnelsManager: cache access to configuration object
Supposedly we never change it once per object, so we do the objective C
hack of adding it cached to the extension. This prevents 1000s of calls
to the keychain and improves the speed of imports.
Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
Diffstat (limited to '')
-rw-r--r-- | WireGuard/WireGuard/Tunnel/TunnelsManager.swift | 10 |
1 files changed, 9 insertions, 1 deletions
diff --git a/WireGuard/WireGuard/Tunnel/TunnelsManager.swift b/WireGuard/WireGuard/Tunnel/TunnelsManager.swift index 93f75ff..6bcf6f7 100644 --- a/WireGuard/WireGuard/Tunnel/TunnelsManager.swift +++ b/WireGuard/WireGuard/Tunnel/TunnelsManager.swift @@ -526,7 +526,15 @@ class TunnelContainer: NSObject { } extension NETunnelProviderManager { + private static var cachedConfigKey: UInt8 = 0 var tunnelConfiguration: TunnelConfiguration? { - return (protocolConfiguration as? NETunnelProviderProtocol)?.asTunnelConfiguration(called: localizedDescription) + if let cached = objc_getAssociatedObject(self, &NETunnelProviderManager.cachedConfigKey) as? TunnelConfiguration { + return cached + } + let config = (protocolConfiguration as? NETunnelProviderProtocol)?.asTunnelConfiguration(called: localizedDescription) + if config != nil { + objc_setAssociatedObject(self, &NETunnelProviderManager.cachedConfigKey, config, objc_AssociationPolicy.OBJC_ASSOCIATION_RETAIN_NONATOMIC) + } + return config } } |