Skip to content

Commit 86d2533

Browse files
authored
Optimize the opening of really large LCP publications (#640)
1 parent 3bfe899 commit 86d2533

File tree

9 files changed

+13
-20
lines changed

9 files changed

+13
-20
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,10 @@ All notable changes to this project will be documented in this file. Take a look
1818

1919
### Fixed
2020

21+
#### Streamer
22+
23+
* [#639](https://github.com/readium/swift-toolkit/issues/639) Optimized the opening of really large LCP protected publications.
24+
2125
#### Navigator
2226

2327
* [#70](https://github.com/readium/swift-toolkit/issues/70) Fixed restoring the reading progression with RTL EPUB.

Sources/Navigator/Audiobook/PublicationMediaLoader.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ final class PublicationMediaLoader: NSObject, AVAssetResourceLoaderDelegate, Log
5454
dispatchPrecondition(condition: .onQueue(queue))
5555

5656
let href = href.anyURL.normalized
57-
if let res = resources[equivalent: href] {
57+
if let res = resources[href] {
5858
return res
5959
}
6060

Sources/Navigator/EPUB/EPUBNavigatorViewController.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -667,7 +667,7 @@ open class EPUBNavigatorViewController: InputObservableViewController,
667667
: max(firstPositionIndex, Int(ceil(lastProgressionInLastResource * Double(positionsOfLastResource.count - 1))) - 1)
668668

669669
location = await positionsOfFirstResource[firstPositionIndex].copy(
670-
title: tableOfContentsTitleByHref[equivalent: link.url()],
670+
title: tableOfContentsTitleByHref[link.url()],
671671
locations: { $0.progression = firstProgressionInFirstResource }
672672
)
673673

Sources/Shared/Toolkit/URL/URLProtocol.swift

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -170,15 +170,3 @@ private extension String {
170170
return segments.joined(separator: "/")
171171
}
172172
}
173-
174-
public extension Dictionary where Key: URLProtocol {
175-
/// Returns the value of the first key matching `key` after normalization.
176-
subscript<T: URLConvertible>(equivalent key: T) -> Value? {
177-
for (k, v) in self {
178-
if k.isEquivalentTo(key) {
179-
return v
180-
}
181-
}
182-
return nil
183-
}
184-
}

Sources/Streamer/Parser/Audio/AudioParser.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ public final class AudioParser: PublicationParser {
9191
container.entries
9292
.compactMap { url -> (AnyURL, Format)? in
9393
guard
94-
let format = formats[equivalent: url],
94+
let format = formats[url],
9595
format.conformsToAny(audioSpecifications)
9696
else {
9797
return nil

Sources/Streamer/Parser/EPUB/EPUBEncryptionParser.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ final class EPUBEncryptionParser: Loggable {
5050
let algorithm = encryptedDataElement.firstChild(xpath: "enc:EncryptionMethod")?.attr("Algorithm"),
5151
let resourceURI = encryptedDataElement.firstChild(xpath: "enc:CipherData/enc:CipherReference")?.attr("URI")
5252
.flatMap(RelativeURL.init(epubHREF:))
53+
.map(\.normalized)
5354
else {
5455
continue
5556
}

Sources/Streamer/Parser/EPUB/OPFParser.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -192,7 +192,7 @@ final class OPFParser: Loggable {
192192
private func makeLink(manifestItem: ReadiumFuzi.XMLElement, spineItem: ReadiumFuzi.XMLElement?, isCover: Bool) -> Link? {
193193
guard
194194
let relativeHref = manifestItem.attr("href").flatMap(RelativeURL.init(epubHREF:)),
195-
let href = baseURL.resolve(relativeHref)
195+
let href = baseURL.resolve(relativeHref)?.normalized
196196
else {
197197
return nil
198198
}
@@ -212,7 +212,7 @@ final class OPFParser: Loggable {
212212

213213
var properties = parseStringProperties(stringProperties)
214214

215-
if let encryption = encryptions[equivalent: href]?.json, !encryption.isEmpty {
215+
if let encryption = encryptions[href]?.json, !encryption.isEmpty {
216216
properties["encrypted"] = encryption
217217
}
218218

Sources/Streamer/Parser/EPUB/Resource Transformers/EPUBDeobfuscator.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,9 +33,9 @@ final class EPUBDeobfuscator {
3333
func deobfuscate(resource: Resource, at href: AnyURL) -> Resource {
3434
// Checks if the resource is obfuscated with a known algorithm.
3535
guard
36-
let href = href.relativeURL,
36+
let href = href.relativeURL?.normalized,
3737
!publicationId.isEmpty, publicationId != "urn:uuid:",
38-
let algorithmId = encryptions[equivalent: href]?.algorithm,
38+
let algorithmId = encryptions[href]?.algorithm,
3939
let algorithm = algorithms.first(withIdentifier: algorithmId)
4040
else {
4141
return resource

Sources/Streamer/Parser/Image/ImageParser.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ public final class ImageParser: PublicationParser {
8686
container.entries
8787
.compactMap { url -> (AnyURL, Format)? in
8888
guard
89-
let format = formats[equivalent: url],
89+
let format = formats[url],
9090
format.conformsToAny(bitmapSpecifications)
9191
else {
9292
return nil

0 commit comments

Comments
 (0)