From f78fba4b10df9db437a387499ee1a7d4e2e08da7 Mon Sep 17 00:00:00 2001 From: NachoSoto Date: Tue, 13 Jun 2023 11:20:37 -0700 Subject: [PATCH] `copy(with: VerificationResult)`: optimization to avoid copies I noticed this could be improved while working on #2635. --- Sources/Identity/CustomerInfo.swift | 2 ++ Sources/Networking/HTTPClient/HTTPResponse.swift | 2 ++ 2 files changed, 4 insertions(+) diff --git a/Sources/Identity/CustomerInfo.swift b/Sources/Identity/CustomerInfo.swift index c194ed9570..ef84c9b6e3 100644 --- a/Sources/Identity/CustomerInfo.swift +++ b/Sources/Identity/CustomerInfo.swift @@ -238,6 +238,8 @@ extension CustomerInfo { /// Creates a copy of this ``CustomerInfo`` modifying only the ``VerificationResult``. func copy(with entitlementVerification: VerificationResult) -> Self { + guard entitlementVerification != self.data.entitlementVerification else { return self } + var copy = self.data copy.entitlementVerification = entitlementVerification return .init(data: copy) diff --git a/Sources/Networking/HTTPClient/HTTPResponse.swift b/Sources/Networking/HTTPClient/HTTPResponse.swift index 5962d9fc0f..9c2ba47453 100644 --- a/Sources/Networking/HTTPClient/HTTPResponse.swift +++ b/Sources/Networking/HTTPClient/HTTPResponse.swift @@ -98,6 +98,8 @@ extension HTTPResponse { } func copy(with newVerificationResult: VerificationResult) -> Self { + guard newVerificationResult != self.verificationResult else { return self } + return .init( statusCode: self.statusCode, responseHeaders: self.responseHeaders,