mirror of
https://github.com/MariaDB/server.git
synced 2025-08-05 13:16:09 +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:
@@ -69,6 +69,29 @@ enum enum_used_fields
|
||||
};
|
||||
|
||||
|
||||
/*
|
||||
Allocate string field in MEM_ROOT and return it as String
|
||||
|
||||
SYNOPSIS
|
||||
get_field()
|
||||
mem MEM_ROOT for allocating
|
||||
field Field for retrieving of string
|
||||
res result String
|
||||
*/
|
||||
|
||||
static void get_field(MEM_ROOT *mem, Field *field, String *res)
|
||||
{
|
||||
THD *thd= field->get_thd();
|
||||
Sql_mode_instant_remove sms(thd, MODE_PAD_CHAR_TO_FULL_LENGTH);
|
||||
LEX_STRING ls= field->val_lex_string_strmake(mem);
|
||||
DBUG_ASSERT((!ls.str && !ls.length) || ls.str[ls.length] == '\0');
|
||||
if (!ls.str)
|
||||
res->length(0); // EOM
|
||||
else
|
||||
res->set((const char *) ls.str, ls.length, field->charset());
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
Fill st_find_field structure with pointers to fields
|
||||
|
||||
|
Reference in New Issue
Block a user