Skip to content

Commit

Permalink
[mysql-5.6][PR] use lambda instead of std::bind
Browse files Browse the repository at this point in the history
Summary:
std::bind(yield_condition, table) will generate a functor which size is larger than std::function's local buf, thus std::function needs to new/delete memory to store the functor.

This PR use the lambda which just capture one pointer(table), which size can fit into std::function's local buf thus new/delete is not needed.

Pull Request resolved: facebook#1243
GitHub Author: leipeng <peng@topling.cn>

Test Plan: Imported from GitHub, without a `Test Plan:` line.

Reviewers: mung

Reviewed By: mung

Subscribers: pgl, webscalesql-eng@fb.com

Differential Revision: https://phabricator.intern.facebook.com/D40858532

Tags: mysql80, accept2ship
  • Loading branch information
hermanlee authored and Herman Lee committed Nov 4, 2022
1 parent 40e7bcb commit f7431f7
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 3 deletions.
4 changes: 2 additions & 2 deletions sql/handler.cc
Original file line number Diff line number Diff line change
Expand Up @@ -2912,7 +2912,7 @@ void handler::ha_statistic_increment(
(table->in_use->status_var.*offset)++;
table->in_use->check_limit_rows_examined();
table->in_use->update_sql_stats_periodic();
table->in_use->check_yield(std::bind(yield_condition, table));
table->in_use->check_yield([t = table] { return yield_condition(t); });
}
}

Expand Down Expand Up @@ -6502,7 +6502,7 @@ ha_rows handler::multi_range_read_info_const(uint keyno, RANGE_SEQ_IF *seq,
while (!seq->next(seq_it, &range)) {
if (unlikely(thd->killed != 0)) return HA_POS_ERROR;

thd->check_yield(std::bind(yield_condition, table));
thd->check_yield([t = table] { return yield_condition(t); });

n_ranges++;
key_range *min_endp, *max_endp;
Expand Down
2 changes: 1 addition & 1 deletion sql/sql_class.cc
Original file line number Diff line number Diff line change
Expand Up @@ -2733,7 +2733,7 @@ void THD::restore_sub_statement_state(Sub_statement_state *backup) {
}

void THD::check_yield(std::function<bool()> cond) {
yield_cond = cond;
yield_cond = std::move(cond);
thd_wait_begin(this, THD_WAIT_YIELD);
thd_wait_end(this);
yield_cond = nullptr;
Expand Down

0 comments on commit f7431f7

Please sign in to comment.