perf(reader): M30 删掉无人消费的下一页预取槽(refill 渲染减半、常驻 −0.69MB)+ 回书架置顶刚读完的书

This commit is contained in:
AskaEth committed 2026-11-10 13:22:35 +08:00
1 parent dc559aa1ac
commit a9638fa59c
5 files changed
+73 -34

No files matched your search

+32 -4
View File
@@ -17,8 +17,9 @@
* M29 性能(用户反馈「几百本书首页卡得飞起」):
* - **扫描结果进程内缓存**:只在本进程首次进入书架时扫 Books/;从阅读页返回不再重扫
* (真机 exFAT 全量扫描 3.1s,是「回书架冻结」的唯一大头)。顶栏「刷新」强制重扫。
* 行为变化:新放进 Books/ 的书、以及刚读完那本书的「最近阅读置顶」需点一次「刷新」才更新。
* 行为变化:新放进 Books/ 的书需点一次「刷新」才出现。
* - **行数多时关圆角容器**(见 SHELF_ROUND_MAX_ROWS):圆角卡逐像素填充,595 本时滑一步 46ms。
* M30:M29 的「刚读完不置顶」缺口补上(只刷一本书的 ts + 内存重排,不重扫全盘)。
*/
#include "../reader_internal.h"
#include "progress.h"
@@ -39,6 +40,8 @@ static shelf_book g_books[SHELF_MAX_BOOKS];
static int g_nbooks;
static int g_scanned; /* 1=本进程已扫过 Books/(进书架缓存;「刷新」动作强制重扫) */
static int g_active;
/* M30:刚打开过的书(返回书架时只刷这一本的 ts 并重排,避免为「最近阅读置顶」重扫全盘)。 */
static char g_just_read[400];
static meow_widget *g_list; /* listview(布局=list) */
static meow_lazygrid *g_grid; /* lazygrid(布局=grid) */
static meow_widget *g_appbar; /* meow_topappbar */
@@ -111,6 +114,23 @@ static void build_rows(void)
g_nrows = shelf_build_rows(g_books, g_nbooks, g_group_folder, g_rows, SHELF_MAX_ROWS);
}
/* M30:从阅读页返回时把「刚读完」置顶。只读这一本的进度文件 + 重排内存里的 g_books,
* 不 opendir/不遍历目录(对比全量重扫真机 3s)。重排后 on_enter 照常 build_rows + 重建控件。 */
static void promote_just_read(void)
{
if (!g_just_read[0]) return;
for (int i = 0; i < g_nbooks; i++) {
if (strcmp(g_books[i].path, g_just_read) != 0) continue;
uint64_t ts = shelf_ts_of(g_books[i].path);
if (ts > g_books[i].ts) {
g_books[i].ts = ts;
shelf_sort_recent(g_books, g_nbooks);
}
break;
}
g_just_read[0] = 0;
}
/* ---- list 数据源(vsource + 段头;container on) ---- */
static int shelf_list_count(void *ctx) { (void)ctx; return g_nrows; }
static void shelf_list_bind(int idx, meow_lv_item *item, void *ctx)
@@ -147,7 +167,10 @@ static void shelf_list_tapcb(int idx, int op, void *ctx)
if (bi < 0 || bi >= g_nbooks) return;
/* 点书开读:reader_open 打开书(含页位图)→ push ACT_READER 让阅读页成为 view activity,
* 驱动 reader_on_enter/on_leave(重建/释放页位图);「返回书架」/左缘返回走 page_pop 回书架。 */
if (reader_open(g_books[bi].path) == 0) meow_view_page_push(ACT_READER);
if (reader_open(g_books[bi].path) == 0) {
snprintf(g_just_read, sizeof g_just_read, "%s", g_books[bi].path); /* 返回时置顶用 */
meow_view_page_push(ACT_READER);
}
}
/* ---- grid 数据源(meow_lazygrid,4 列封面卡) ---- */
@@ -204,7 +227,10 @@ static void shelf_grid_tapcb(int idx, void *ctx)
{
(void)ctx;
if (idx < 0 || idx >= g_nbooks) return;
if (reader_open(g_books[idx].path) == 0) meow_view_page_push(ACT_READER);
if (reader_open(g_books[idx].path) == 0) {
snprintf(g_just_read, sizeof g_just_read, "%s", g_books[idx].path); /* 返回时置顶用 */
meow_view_page_push(ACT_READER);
}
}
/* ---- 控件装配(按当前布局重建 list / grid) ---- */
@@ -274,9 +300,11 @@ static void shelf_on_enter(meow_view *v, void *ctx)
g_group_folder = (c && strcmp(c->shelf_group, "folder") == 0) ? 1 : 0;
/* 书架缓存:本进程只在首次进入时扫一次 Books/(从阅读页返回不再重扫)。
* 扫描在真机是 3.1s(exFAT 434 目录 opendir/readdir),是「回书架冻结」的唯一大头。
* 代价:新放入的书 / 刚读完的书不会自动置顶,需点顶栏「刷新」(强制重扫)。
* 代价:新放入的书不会自动出现,需点顶栏「刷新」(强制重扫)。
* M30:刚读完那本例外——promote_just_read() 只读它一个进度文件并重排,低成本置顶。
* 提示条(超上限截断 / 超深目录)语义不变:首次扫描时算好并保留在 g_notice*。 */
if (!g_scanned) scan_books();
else promote_just_read();
build_rows();
const meow_theme *th = meow_theme_get();
g_bg = th->bg; g_fg = th->fg; g_dim = th->dim;