Get rid of unnecessary clone when constructing page token
What changed, and why it matters
This is a minor code cleanup that removes an unnecessary clone of string keys when building a paginated list response. It changes the order of operations so the same data is moved rather than duplicated, with no functional change to behavior or outputs.
No security action needed. Treat as a normal code-quality/performance improvement.
Security signals we found
No strong security signals were identified.
Evidence from the diff
The patch refactors FilesystemStoreState::list in lightning-persister/src/fs_store/v2.rs. Previously, page_entries was cloned from entries, then keys was cloned from page_entries, and finally next_page_token borrowed from page_entries. The new code constructs next_page_token while page_entries still exists, then consumes page_entries via into_iter() to build keys without cloning. This is a pure performance/cleanup refactor with identical semantics.
Changed components
lightning-persister/src/fs_store/v2.rsInspect captured patch +2 / −2
diff --git a/lightning-persister/src/fs_store/v2.rs b/lightning-persister/src/fs_store/v2.rs
index 7cff1d3..4260387 100644
--- a/lightning-persister/src/fs_store/v2.rs
+++ b/lightning-persister/src/fs_store/v2.rs
@@ -146,8 +146,6 @@ impl FilesystemStoreState {
let page_entries: Vec<_> =
entries.iter().skip(start_idx).take(PAGE_SIZE).cloned().collect();
- let keys: Vec<String> = page_entries.iter().map(|(_, key)| key.clone()).collect();
-
// Determine next page token
let next_page_token = if start_idx + PAGE_SIZE < entries.len() {
page_entries.last().map(|(mtime, key)| PageToken::new(format_page_token(*mtime, key)))
@@ -155,6 +153,8 @@ impl FilesystemStoreState {
None
};
+ let keys: Vec<String> = page_entries.into_iter().map(|(_, key)| key).collect();
+
Ok(PaginatedListResponse { keys, next_page_token })
}
}
Why this scored 15/100
Community notes
Notes can correct, qualify, or add evidence to the AI analysis. Every note shown here has been validated by a human moderator.
The AI analysis stands alone for now. Submit a note if you can add evidence or important context.