Commit dc8380b6 authored by Marko Mäkelä's avatar Marko Mäkelä

MDEV-14602: Cleanup recv_dblwr_t::find_page()

Avoid creating std::vector, and use single instead of double traversal.
parent 2350066e
...@@ -27,7 +27,6 @@ Created 9/20/1997 Heikki Tuuri ...@@ -27,7 +27,6 @@ Created 9/20/1997 Heikki Tuuri
#include "univ.i" #include "univ.i"
#include <vector>
#include <map> #include <map>
#include <string> #include <string>
#include <my_service_manager.h> #include <my_service_manager.h>
...@@ -4044,44 +4043,26 @@ recv_recovery_rollback_active(void) ...@@ -4044,44 +4043,26 @@ recv_recovery_rollback_active(void)
@param[in] page_no page number @param[in] page_no page number
@return page frame @return page frame
@retval NULL if no page was found */ @retval NULL if no page was found */
const byte* const byte*
recv_dblwr_t::find_page(ulint space_id, ulint page_no) recv_dblwr_t::find_page(ulint space_id, ulint page_no)
{ {
typedef std::vector<const byte*, ut_allocator<const byte*> > const byte *result= NULL;
matches_t; lsn_t max_lsn= 0;
matches_t matches;
const byte* result = 0;
for (list::iterator i = pages.begin(); i != pages.end(); ++i) {
if (page_get_space_id(*i) == space_id
&& page_get_page_no(*i) == page_no) {
matches.push_back(*i);
}
}
if (matches.size() == 1) {
result = matches[0];
} else if (matches.size() > 1) {
lsn_t max_lsn = 0;
lsn_t page_lsn = 0;
for (matches_t::iterator i = matches.begin(); for (list::const_iterator i = pages.begin(); i != pages.end(); ++i)
i != matches.end(); {
++i) { const byte *page= *i;
if (page_get_page_no(page) != page_no ||
page_lsn = mach_read_from_8(*i + FIL_PAGE_LSN); page_get_space_id(page) != space_id)
continue;
if (page_lsn > max_lsn) { const lsn_t lsn= mach_read_from_8(page + FIL_PAGE_LSN);
max_lsn = page_lsn; if (lsn <= max_lsn)
result = *i; continue;
} max_lsn= lsn;
} result= page;
} }
return(result); return result;
} }
#ifndef DBUG_OFF #ifndef DBUG_OFF
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment