Skip to content

Commit

Permalink
Optimize make_lex_string() to not call alloc_root twice.
Browse files Browse the repository at this point in the history
  • Loading branch information
montywi authored and vuvova committed Aug 23, 2017
1 parent 8bfda2f commit af06683
Showing 1 changed file with 18 additions and 4 deletions.
22 changes: 18 additions & 4 deletions sql/sql_class.h
Original file line number Diff line number Diff line change
Expand Up @@ -3368,17 +3368,31 @@ class THD :public Statement,
LEX_STRING *make_lex_string(const char* str, uint length)
{
LEX_STRING *lex_str;
if (!(lex_str= (LEX_STRING *)alloc_root(mem_root, sizeof(LEX_STRING))))
char *tmp;
if (!(lex_str= (LEX_STRING *) alloc_root(mem_root, sizeof(LEX_STRING) +
length+1)))
return 0;
return make_lex_string(lex_str, str, length);
tmp= (char*) (lex_str+1);
lex_str->str= tmp;
memcpy(tmp, str, length);
tmp[length]= 0;
lex_str->length= length;
return lex_str;
}

LEX_CSTRING *make_clex_string(const char* str, uint length)
{
LEX_CSTRING *lex_str;
if (!(lex_str= (LEX_CSTRING *)alloc_root(mem_root, sizeof(LEX_CSTRING))))
char *tmp;
if (!(lex_str= (LEX_CSTRING *)alloc_root(mem_root, sizeof(LEX_CSTRING) +
length+1)))
return 0;
return make_lex_string(lex_str, str, length);
tmp= (char*) (lex_str+1);
lex_str->str= tmp;
memcpy(tmp, str, length);
tmp[length]= 0;
lex_str->length= length;
return lex_str;
}

// Allocate LEX_STRING for character set conversion
Expand Down

0 comments on commit af06683

Please sign in to comment.