完善搜索定位与内存监测回归验证
本次提交围绕搜索链路的稳定性、定位恢复体验以及长章节内存优化的验证能力进行了补强。 主要改动: 1. 调整阅读器搜索栏、搜索协调器与定位恢复逻辑,改善搜索结果跳转、状态同步与相关 UI 行为。 2. 补充内存探针接入点与上下文记录,便于跟踪阅读过程中的内存占用变化。 3. 更新 RDURLReaderController、ReaderContext 与工具视图相关实现,使调试与观测链路更完整。 4. 新增 MemoryFootprintTests,并同步更新 DemoReaderState 与 SearchTests,用 UI 测试覆盖搜索与内存相关回归场景。
This commit is contained in:
@@ -22,8 +22,13 @@ enum RDEPUBMemoryProbe {
|
||||
|
||||
static func log(_ event: String) {
|
||||
guard isEnabled else { return }
|
||||
let megabytes = Double(currentFootprint()) / 1_048_576
|
||||
print(String(format: "[EPUB][MemoryProbe] %@ footprint=%.1fMB", event, megabytes))
|
||||
print(String(format: "[EPUB][MemoryProbe] %@ footprint=%.1fMB", event, footprintMB))
|
||||
}
|
||||
|
||||
/// Current phys_footprint in MB. Cheap enough (one task_info call) to
|
||||
/// surface in the demo state snapshot for automated memory assertions.
|
||||
static var footprintMB: Double {
|
||||
Double(currentFootprint()) / 1_048_576
|
||||
}
|
||||
|
||||
/// phys_footprint matches the value Xcode's memory gauge and Jetsam use.
|
||||
|
||||
@@ -377,10 +377,12 @@ final class RDEPUBReaderContext {
|
||||
}
|
||||
|
||||
func textChapterData(forNormalizedHref href: String) -> RDEPUBChapterData? {
|
||||
guard let textBook, let publication else { return nil }
|
||||
let normalizedHref = publication.resourceResolver.normalizedHref(href) ?? href
|
||||
guard let textBook else { return nil }
|
||||
// External text books (e.g. plain .txt) have no publication; their
|
||||
// chapter hrefs are matched verbatim.
|
||||
let normalizedHref = publication?.resourceResolver.normalizedHref(href) ?? href
|
||||
return textBook.chapters.lazy
|
||||
.first(where: { (publication.resourceResolver.normalizedHref($0.href) ?? $0.href) == normalizedHref })
|
||||
.first(where: { (publication?.resourceResolver.normalizedHref($0.href) ?? $0.href) == normalizedHref })
|
||||
.flatMap { textBook.chapterData(for: $0.href) }
|
||||
}
|
||||
|
||||
|
||||
@@ -143,6 +143,12 @@ final class RDEPUBReaderSearchCoordinator {
|
||||
if let textBook = controller.textBook, let publication = controller.publication {
|
||||
return .textBook(textBook, publication)
|
||||
}
|
||||
// External text books (e.g. plain .txt) carry a textBook but no
|
||||
// publication/parser/bookPageMap; search over the chapter text
|
||||
// directly using hrefs from the textBook itself.
|
||||
if let textBook = controller.textBook {
|
||||
return .externalTextBook(textBook)
|
||||
}
|
||||
if controller.readerContext.bookPageMap != nil, let publication = controller.publication {
|
||||
return .onDemand(publication)
|
||||
}
|
||||
@@ -157,6 +163,8 @@ final class RDEPUBReaderSearchCoordinator {
|
||||
switch engine {
|
||||
case .textBook(let textBook, let publication):
|
||||
return RDEPUBTextSearchEngine(textBook: textBook, publication: publication).search(keyword: keyword)
|
||||
case .externalTextBook(let textBook):
|
||||
return RDEPUBTextSearchEngine.searchWithoutPublication(textBook: textBook, keyword: keyword)
|
||||
case .onDemand(let publication):
|
||||
return resolvedOnDemandSearchMatches(for: keyword, publication: publication, layoutSnapshot: layoutSnapshot)
|
||||
case .html(let parser, let publication):
|
||||
@@ -166,6 +174,7 @@ final class RDEPUBReaderSearchCoordinator {
|
||||
|
||||
private enum SearchEngineSnapshot {
|
||||
case textBook(RDEPUBTextBook, RDEPUBPublication)
|
||||
case externalTextBook(RDEPUBTextBook)
|
||||
case onDemand(RDEPUBPublication)
|
||||
case html(RDEPUBParser, RDEPUBPublication)
|
||||
}
|
||||
@@ -350,12 +359,16 @@ final class RDEPUBReaderSearchCoordinator {
|
||||
rangeCFI: searchMatch.rangeCFI
|
||||
)
|
||||
|
||||
if let textBook = controller.textBook, let publication = controller.publication {
|
||||
return textBook.pageNumber(
|
||||
for: location,
|
||||
resolver: publication.resourceResolver,
|
||||
bookIdentifier: controller.currentBookIdentifier
|
||||
)
|
||||
if let textBook = controller.textBook {
|
||||
if let publication = controller.publication {
|
||||
return textBook.pageNumber(
|
||||
for: location,
|
||||
resolver: publication.resourceResolver,
|
||||
bookIdentifier: controller.currentBookIdentifier
|
||||
)
|
||||
}
|
||||
// External text books have no resolver; hrefs match verbatim.
|
||||
return textBook.chapterData(for: location.href)?.pageNumber(for: location)
|
||||
}
|
||||
|
||||
return controller.readingSession?.pageIndex(
|
||||
|
||||
Reference in New Issue
Block a user