try speeding up jump_to_page
This commit is contained in:
parent
c664d461aa
commit
84a9266f4b
1 changed files with 31 additions and 5 deletions
|
@ -178,11 +178,37 @@ Page_Info_Node *viewer_jump_to_page(App_State &app, u64 page_idx)
|
||||||
return nullptr;
|
return nullptr;
|
||||||
page_idx = (page_idx + app.rndata.n_pages) % app.rndata.n_pages;
|
page_idx = (page_idx + app.rndata.n_pages) % app.rndata.n_pages;
|
||||||
|
|
||||||
// @Speed
|
// // @Speed
|
||||||
Page_Info_Node *page = app.rndata.pages;
|
// Page_Info_Node *page = app.rndata.pages;
|
||||||
for (u64 i = 0; i < page_idx; ++i) {
|
// for (u64 i = 0; i < page_idx; ++i) {
|
||||||
page = page->next;
|
// page = page->next;
|
||||||
assert(page);
|
// assert(page);
|
||||||
|
// }
|
||||||
|
|
||||||
|
// Find the page_idx-th page. We could just iterate n times over the pages list,
|
||||||
|
// but skimming through the clusters first should be faster in most cases.
|
||||||
|
Page_Info_Node *page = nullptr;
|
||||||
|
for (u64 i = 0; i < app.rndata.n_clusters - 1; ++i) {
|
||||||
|
const Cluster_Info &cluster = app.rndata.clusters[i];
|
||||||
|
const Cluster_Info &next_cluster = app.rndata.clusters[i];
|
||||||
|
if (cluster.first_page_idx <= page_idx && page_idx < next_cluster.first_page_idx) {
|
||||||
|
u64 idx_in_cluster = page_idx - cluster.first_page_idx;
|
||||||
|
page = cluster.first_page;
|
||||||
|
for (u64 j = 0; j < idx_in_cluster; ++j) {
|
||||||
|
page = page->next;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (!page) {
|
||||||
|
// page was not in the first N - 1 clusters, so it must be in the last one.
|
||||||
|
const Cluster_Info &cluster = app.rndata.clusters[app.rndata.n_clusters - 1];
|
||||||
|
assert(page_idx >= cluster.first_page_idx);
|
||||||
|
u64 idx_in_cluster = page_idx - cluster.first_page_idx;
|
||||||
|
page = cluster.first_page;
|
||||||
|
for (u64 j = 0; j < idx_in_cluster; ++j) {
|
||||||
|
page = page->next;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
app.viewer.latest_page_gone_to = page_idx;
|
app.viewer.latest_page_gone_to = page_idx;
|
||||||
|
|
Loading…
Add table
Reference in a new issue