Commit bd36a4ca authored by Eugene Kosov's avatar Eugene Kosov

introduce HASH_REPLACE() for hash_table_t

HASH_REPLACE(): allows to not travel through linked list twice
when HASH_INSERT() happens right after HASH_DELETE()
parent 256994ef
...@@ -2212,8 +2212,8 @@ buf_page_realloc( ...@@ -2212,8 +2212,8 @@ buf_page_realloc(
ut_d(block->page.in_page_hash = FALSE); ut_d(block->page.in_page_hash = FALSE);
ulint fold = block->page.id.fold(); ulint fold = block->page.id.fold();
ut_ad(fold == new_block->page.id.fold()); ut_ad(fold == new_block->page.id.fold());
HASH_DELETE(buf_page_t, hash, buf_pool->page_hash, fold, (&block->page)); HASH_REPLACE(buf_page_t, hash, buf_pool->page_hash, fold,
HASH_INSERT(buf_page_t, hash, buf_pool->page_hash, fold, (&new_block->page)); &block->page, &new_block->page);
ut_ad(new_block->page.in_page_hash); ut_ad(new_block->page.in_page_hash);
...@@ -3329,8 +3329,8 @@ buf_relocate( ...@@ -3329,8 +3329,8 @@ buf_relocate(
/* relocate buf_pool->page_hash */ /* relocate buf_pool->page_hash */
ulint fold = bpage->id.fold(); ulint fold = bpage->id.fold();
ut_ad(fold == dpage->id.fold()); ut_ad(fold == dpage->id.fold());
HASH_DELETE(buf_page_t, hash, buf_pool->page_hash, fold, bpage); HASH_REPLACE(buf_page_t, hash, buf_pool->page_hash, fold, bpage,
HASH_INSERT(buf_page_t, hash, buf_pool->page_hash, fold, dpage); dpage);
} }
/** Hazard Pointer implementation. */ /** Hazard Pointer implementation. */
......
...@@ -184,6 +184,18 @@ do {\ ...@@ -184,6 +184,18 @@ do {\
HASH_INVALIDATE(DATA, NAME);\ HASH_INVALIDATE(DATA, NAME);\
} while (0) } while (0)
#define HASH_REPLACE(TYPE, NAME, TABLE, FOLD, DATA_OLD, DATA_NEW) \
do { \
(DATA_NEW)->NAME = (DATA_OLD)->NAME; \
\
hash_cell_t& cell3333 \
= TABLE->array[hash_calc_hash(FOLD, TABLE)]; \
TYPE** struct3333 = (TYPE**)&cell3333.node; \
while (*struct3333 != DATA_OLD) { \
struct3333 = &((*struct3333)->NAME); \
} \
*struct3333 = DATA_NEW; \
} while (0)
/*******************************************************************//** /*******************************************************************//**
Gets the first struct in a hash chain, NULL if none. */ Gets the first struct in a hash chain, NULL if none. */
......
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