Skip to content

Commit 4304960

Browse files
committed
fix a performance bug
1 parent 802d7d5 commit 4304960

File tree

1 file changed

+7
-9
lines changed

1 file changed

+7
-9
lines changed

handlersocket/database.cpp

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -183,6 +183,8 @@ struct dbcontext : public dbcontext_i, private noncopyable {
183183
std::vector<char> info_message_buf;
184184
table_vec_type table_vec;
185185
table_map_type table_map;
186+
String val_buffer;
187+
String val_ptr;
186188
};
187189

188190
database::database(const config& c)
@@ -518,8 +520,6 @@ void
518520
dbcontext::resp_record(dbcallback_i& cb, TABLE *const table,
519521
const prep_stmt& pst)
520522
{
521-
char rwpstr_buf[64];
522-
String rwpstr(rwpstr_buf, sizeof(rwpstr_buf), &my_charset_bin);
523523
const prep_stmt::fields_type& rf = pst.get_ret_fields();
524524
const size_t n = rf.size();
525525
for (size_t i = 0; i < n; ++i) {
@@ -530,11 +530,11 @@ dbcontext::resp_record(dbcallback_i& cb, TABLE *const table,
530530
/* null */
531531
cb.dbcb_resp_entry(0, 0);
532532
} else {
533-
fld->val_str(&rwpstr, &rwpstr);
534-
const size_t len = rwpstr.length();
533+
String *const val = fld->val_str(&val_buffer, &val_ptr);
534+
const size_t len = val->length();
535535
if (len != 0) {
536536
/* non-empty */
537-
cb.dbcb_resp_entry(rwpstr.ptr(), rwpstr.length());
537+
cb.dbcb_resp_entry(val->ptr(), val->length());
538538
} else {
539539
/* empty */
540540
static const char empty_str[] = "";
@@ -548,8 +548,6 @@ void
548548
dbcontext::dump_record(dbcallback_i& cb, TABLE *const table,
549549
const prep_stmt& pst)
550550
{
551-
char rwpstr_buf[64];
552-
String rwpstr(rwpstr_buf, sizeof(rwpstr_buf), &my_charset_bin);
553551
const prep_stmt::fields_type& rf = pst.get_ret_fields();
554552
const size_t n = rf.size();
555553
for (size_t i = 0; i < n; ++i) {
@@ -559,8 +557,8 @@ dbcontext::dump_record(dbcallback_i& cb, TABLE *const table,
559557
/* null */
560558
fprintf(stderr, "NULL");
561559
} else {
562-
fld->val_str(&rwpstr, &rwpstr);
563-
const std::string s(rwpstr.ptr(), rwpstr.length());
560+
String *const val = fld->val_str(&val_buffer, &val_ptr);
561+
const std::string s(val->ptr(), val->length());
564562
fprintf(stderr, "[%s]", s.c_str());
565563
}
566564
}

0 commit comments

Comments
 (0)