Skip to content

Commit ecdc75f

Browse files
committed
use emplace instead of find + emplace
1 parent ec8d307 commit ecdc75f

File tree

1 file changed

+4
-3
lines changed

1 file changed

+4
-3
lines changed

storage/rocksdb/ha_rocksdb.cc

+4-3
Original file line numberDiff line numberDiff line change
@@ -7276,8 +7276,8 @@ Rdb_table_handler *Rdb_open_tables_map::get_table_handler(
72767276

72777277
// First, look up the table in the hash map.
72787278
RDB_MUTEX_LOCK_CHECK(m_mutex);
7279-
const auto it = m_table_map.find(table_name_str);
7280-
if (it != m_table_map.end()) {
7279+
const auto [it, success] = m_table_map.emplace(table_name_str, nullptr);
7280+
if (success) {
72817281
// Found it
72827282
table_handler = it->second;
72837283
} else {
@@ -7289,6 +7289,7 @@ Rdb_table_handler *Rdb_open_tables_map::get_table_handler(
72897289
my_multi_malloc(PSI_NOT_INSTRUMENTED, MYF(MY_WME | MY_ZEROFILL),
72907290
&table_handler, sizeof(*table_handler), &tmp_name,
72917291
table_name_str.length() + 1, NullS)))) {
7292+
m_table_map.erase(it); // malloc failing is unlikely
72927293
// Allocating a new Rdb_table_handler and a new table name failed.
72937294
RDB_MUTEX_UNLOCK_CHECK(m_mutex);
72947295
return nullptr;
@@ -7299,7 +7300,7 @@ Rdb_table_handler *Rdb_open_tables_map::get_table_handler(
72997300
table_handler->m_table_name = tmp_name;
73007301
strxmov(table_handler->m_table_name, table_name, NullS);
73017302

7302-
m_table_map.emplace(table_name_str, table_handler);
7303+
it->second = table_handler;
73037304

73047305
thr_lock_init(&table_handler->m_thr_lock);
73057306
table_handler->m_io_perf_read.init();

0 commit comments

Comments
 (0)