summaryrefslogtreecommitdiff
path: root/core/templates
diff options
context:
space:
mode:
authormyaaaaaaaaa <103326468+myaaaaaaaaa@users.noreply.github.com>2023-02-16 14:54:04 -0500
committermyaaaaaaaaa <103326468+myaaaaaaaaa@users.noreply.github.com>2023-02-16 19:58:27 -0500
commit6b0f253a45c325e6100c1e74da503532c7321024 (patch)
tree5b50dc26cc5da0025968dbc4c3ea86d91fe6206f /core/templates
parentd2699dc7ab96fbd75faccc1f32f55baebf1d84dc (diff)
Fix PagedArray.merge_unordered() dropping pages
Diffstat (limited to 'core/templates')
-rw-r--r--core/templates/paged_array.h20
1 files changed, 9 insertions, 11 deletions
diff --git a/core/templates/paged_array.h b/core/templates/paged_array.h
index c447b5af64..45b90869b9 100644
--- a/core/templates/paged_array.h
+++ b/core/templates/paged_array.h
@@ -278,10 +278,10 @@ public:
count -= remainder;
- uint32_t src_pages = p_array._get_pages_in_use();
+ uint32_t src_page_index = 0;
uint32_t page_size = page_size_mask + 1;
- for (uint32_t i = 0; i < src_pages; i++) {
+ while (p_array.count > 0) {
uint32_t page_count = _get_pages_in_use();
uint32_t new_page_count = page_count + 1;
@@ -289,16 +289,14 @@ public:
_grow_page_array(); //keep out of inline
}
- page_data[page_count] = p_array.page_data[i];
- page_ids[page_count] = p_array.page_ids[i];
- if (i == src_pages - 1) {
- //last page, only increment with remainder
- count += p_array.count & page_size_mask;
- } else {
- count += page_size;
- }
+ page_data[page_count] = p_array.page_data[src_page_index];
+ page_ids[page_count] = p_array.page_ids[src_page_index];
+
+ uint32_t take = MIN(p_array.count, page_size); //pages to take away
+ p_array.count -= take;
+ count += take;
+ src_page_index++;
}
- p_array.count = 0; //take away the other array pages
//handle the remainder page if exists
if (remainder_page) {