diff options
author | RĂ©mi Verschelde <remi@verschelde.fr> | 2023-02-17 13:42:01 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-02-17 13:42:01 +0100 |
commit | e80e21b5e8bfb0af04b5d87bfdfc67ffe95121ac (patch) | |
tree | 8fb3ca4769855fa03b71bdbffe1ba90c5e363f8a /core | |
parent | b51290383f2d8e4460ea6a9ad25ded6bc6396fee (diff) | |
parent | 6b0f253a45c325e6100c1e74da503532c7321024 (diff) |
Merge pull request #73460 from myaaaaaaaaa/merge-unordered
Fix PagedArray.merge_unordered() sometimes dropping pages
Diffstat (limited to 'core')
-rw-r--r-- | core/templates/paged_array.h | 20 |
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) { |