mirror of
https://github.com/MariaDB/server.git
synced 2025-07-29 05:21:33 +03:00
MDEV-32013 Add Field::val_lex_string_strmake()
There are two functions to extract a Field::val_str() value as a LEX_STRING or LEX_CSTRING pointing to the data allocated on a MEM_ROOT: char *get_field(MEM_ROOT *mem, Field *field); bool get_field(MEM_ROOT *mem, Field *field, class String *res); The first function requires strlen() calls to make a LEX_CSTRING/LEX_STRING. The second function requires a redundant String buffer, which is used only as a temporary proxy value pointing to a MEM_ROOT fragment (and does not use any String dynamic allocation methods). This patch add a native way to extract a Field::val_str() value as a LEX_STRING or LEX_CSTRING pointing to a MEM_ROOT fragment. It helps to remove redundant strlen() calls and redundant String buffers. - Adding a new method: LEX_STRING Field::val_lex_string_strmake(MEM_ROOT *mem); - Reusing the new method Field::val_lex_string_strmake() in; bool get_field(MEM_ROOT *mem, Field *field, String *res); Also, moving it from table.cc to a static function in sql_help.cc. It is used in sql_help.cc only, and we don't want it to be reused in other parts of the code (to avoid redundant String buffers). - Reusing the new method Field::val_lex_string_strmake() in this function: char *get_field(MEM_ROOT *mem, Field *field); - Replacing get_field() to Field::val_lex_string_strmake() in these files: sql_plugin.cc (redundant String buffers were removed) sql_udf.cc (redundant strlen() calls were removed) Note, this function: char *get_field(MEM_ROOT *mem, Field *field); is still used in a number of files: event_data_objects.cc event_db_repository.cc sql_acl.cc sql_servers.cc These remaining calls will be removed by separate patches, and get_field() will be removed after that.
This commit is contained in:
@ -1883,12 +1883,11 @@ static void plugin_load(MEM_ROOT *tmp_root)
|
||||
while (!(error= read_record_info.read_record()))
|
||||
{
|
||||
DBUG_PRINT("info", ("init plugin record"));
|
||||
String str_name, str_dl;
|
||||
get_field(tmp_root, table->field[0], &str_name);
|
||||
get_field(tmp_root, table->field[1], &str_dl);
|
||||
|
||||
LEX_CSTRING name= {str_name.ptr(), str_name.length()};
|
||||
LEX_CSTRING dl= {str_dl.ptr(), str_dl.length()};
|
||||
DBUG_ASSERT(new_thd == table->field[0]->get_thd());
|
||||
DBUG_ASSERT(new_thd == table->field[1]->get_thd());
|
||||
DBUG_ASSERT(!(new_thd->variables.sql_mode & MODE_PAD_CHAR_TO_FULL_LENGTH));
|
||||
LEX_CSTRING name= table->field[0]->val_lex_string_strmake(tmp_root);
|
||||
LEX_CSTRING dl= table->field[1]->val_lex_string_strmake(tmp_root);
|
||||
|
||||
if (!name.length || !dl.length)
|
||||
continue;
|
||||
|
Reference in New Issue
Block a user