mirror of
https://github.com/xiaoqidun/ofdgo.git
synced 2026-10-29 17:27:08 +08:00
feat(内存占用): 优化数值解析与页面缓存,减少内存分配和重复处理
This commit is contained in:
1 parent
0fd4954547
commit
830378c6e4
2 files changed
+15
-19
No files matched your search
+3
-12
@@ -53,7 +53,6 @@ const state = {
|
||||
pageObserver: null,
|
||||
visiblePages: new Set(),
|
||||
scrollFrame: 0,
|
||||
thumbnailCache: new Map(),
|
||||
thumbnailInFlight: new Set(),
|
||||
thumbnailObserver: null,
|
||||
visibleThumbnails: new Set(),
|
||||
@@ -1549,7 +1548,6 @@ async function processPageRenderQueue() {
|
||||
const page = await callWASM("ofdgoRenderPage", task.index);
|
||||
if (task.openSeq === state.openSeq) {
|
||||
state.pageCache.set(task.index, page);
|
||||
cacheThumbnail(task.index, page.svg);
|
||||
}
|
||||
task.resolve(page);
|
||||
} catch (err) {
|
||||
@@ -1809,7 +1807,7 @@ function renderPageList() {
|
||||
const thumb = document.createElement("span");
|
||||
thumb.className = "thumb-paper";
|
||||
thumb.setAttribute("aria-hidden", "true");
|
||||
setThumbnailContent(thumb, state.thumbnailCache.get(page.index), page.index, openSeq);
|
||||
setThumbnailContent(thumb, state.pageCache.get(page.index)?.svg, page.index, openSeq);
|
||||
|
||||
const label = document.createElement("span");
|
||||
label.className = "thumb-label";
|
||||
@@ -1831,7 +1829,6 @@ function renderPageList() {
|
||||
}
|
||||
|
||||
function resetThumbnails() {
|
||||
state.thumbnailCache.clear();
|
||||
state.visibleThumbnails.clear();
|
||||
state.thumbnailInFlight.clear();
|
||||
if (state.thumbnailObserver) {
|
||||
@@ -1840,12 +1837,6 @@ function resetThumbnails() {
|
||||
}
|
||||
}
|
||||
|
||||
function cacheThumbnail(index, svgText) {
|
||||
if (typeof svgText === "string" && svgText) {
|
||||
state.thumbnailCache.set(index, svgText);
|
||||
}
|
||||
}
|
||||
|
||||
function setThumbnailContent(container, svgText, index, openSeq = state.openSeq) {
|
||||
const renderKey = `${openSeq}:${index}`;
|
||||
if (svgText && container.dataset.renderKey === renderKey) {
|
||||
@@ -1923,7 +1914,7 @@ async function renderThumbnail(index, openSeq = state.openSeq) {
|
||||
if (openSeq !== state.openSeq || !state.doc) {
|
||||
return;
|
||||
}
|
||||
if (state.thumbnailCache.has(index)) {
|
||||
if (state.pageCache.has(index)) {
|
||||
updateThumbnail(index, openSeq);
|
||||
return;
|
||||
}
|
||||
@@ -1956,7 +1947,7 @@ function updateThumbnail(index, openSeq = state.openSeq) {
|
||||
}
|
||||
const thumb = el.pageList.querySelector(`[data-page-index="${index}"] .thumb-paper`);
|
||||
if (thumb) {
|
||||
setThumbnailContent(thumb, state.thumbnailCache.get(index), index, openSeq);
|
||||
setThumbnailContent(thumb, state.pageCache.get(index)?.svg, index, openSeq);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user