From f1375097e32ef04ac1272e184d4c12bbd2e59056 Mon Sep 17 00:00:00 2001 From: Stefan Ceriu Date: Mon, 18 Sep 2023 14:35:50 +0300 Subject: [PATCH] Prevent too much back and forth through the FFI layer when dealing with MediaSources --- .../Media/Provider/MediaSourceProxy.swift | 23 ++++++++----------- 1 file changed, 10 insertions(+), 13 deletions(-) diff --git a/ElementX/Sources/Services/Media/Provider/MediaSourceProxy.swift b/ElementX/Sources/Services/Media/Provider/MediaSourceProxy.swift index d0ecc5afb..17cc69399 100644 --- a/ElementX/Sources/Services/Media/Provider/MediaSourceProxy.swift +++ b/ElementX/Sources/Services/Media/Provider/MediaSourceProxy.swift @@ -24,30 +24,27 @@ struct MediaSourceProxy: Hashable { /// This is optional when loading images and thumbnails in memory. let mimeType: String? + let url: URL! + init(source: MediaSource, mimeType: String?) { underlyingSource = source + url = URL(string: underlyingSource.url()) self.mimeType = mimeType } init(url: URL, mimeType: String?) { underlyingSource = mediaSourceFromUrl(url: url.absoluteString) + self.url = URL(string: underlyingSource.url()) self.mimeType = mimeType } - - var url: URL! { - // Expecting these to always be valid URLs - URL(string: underlyingSource.url()) - } -} - -// MARK: - Hashable - -extension MediaSource: Hashable { - public static func == (lhs: MediaSource, rhs: MediaSource) -> Bool { - lhs.url() == rhs.url() + + // MARK: - Hashable + + public static func == (lhs: MediaSourceProxy, rhs: MediaSourceProxy) -> Bool { + lhs.url == rhs.url } public func hash(into hasher: inout Hasher) { - hasher.combine(url()) + hasher.combine(url) } }