summaryrefslogtreecommitdiff
path: root/sql/item_vers.h
diff options
context:
space:
mode:
authorMonty <monty@mariadb.org>2020-08-12 20:29:55 +0300
committerSergei Golubchik <serg@mariadb.org>2021-05-19 22:27:48 +0200
commitb6ff139aa3457949a5bff10070f5b0e9ac0b43d7 (patch)
tree952135f7f7a7d7bcb446a2ce28f5c8f2de46e205 /sql/item_vers.h
parentb3bc02f923f6002e6a5bd6446b80575292e1b0c7 (diff)
downloadmariadb-git-b6ff139aa3457949a5bff10070f5b0e9ac0b43d7.tar.gz
Reduce usage of strlen()
Changes: - To detect automatic strlen() I removed the methods in String that uses 'const char *' without a length: - String::append(const char*) - Binary_string(const char *str) - String(const char *str, CHARSET_INFO *cs) - append_for_single_quote(const char *) All usage of append(const char*) is changed to either use String::append(char), String::append(const char*, size_t length) or String::append(LEX_CSTRING) - Added STRING_WITH_LEN() around constant string arguments to String::append() - Added overflow argument to escape_string_for_mysql() and escape_quotes_for_mysql() instead of returning (size_t) -1 on overflow. This was needed as most usage of the above functions never tested the result for -1 and would have given wrong results or crashes in case of overflows. - Added Item_func_or_sum::func_name_cstring(), which returns LEX_CSTRING. Changed all Item_func::func_name()'s to func_name_cstring()'s. The old Item_func_or_sum::func_name() is now an inline function that returns func_name_cstring().str. - Changed Item::mode_name() and Item::func_name_ext() to return LEX_CSTRING. - Changed for some functions the name argument from const char * to to const LEX_CSTRING &: - Item::Item_func_fix_attributes() - Item::check_type_...() - Type_std_attributes::agg_item_collations() - Type_std_attributes::agg_item_set_converter() - Type_std_attributes::agg_arg_charsets...() - Type_handler_hybrid_field_type::aggregate_for_result() - Type_handler_geometry::check_type_geom_or_binary() - Type_handler::Item_func_or_sum_illegal_param() - Predicant_to_list_comparator::add_value_skip_null() - Predicant_to_list_comparator::add_value() - cmp_item_row::prepare_comparators() - cmp_item_row::aggregate_row_elements_for_comparison() - Cursor_ref::print_func() - Removes String_space() as it was only used in one cases and that could be simplified to not use String_space(), thanks to the fixed my_vsnprintf(). - Added some const LEX_CSTRING's for common strings: - NULL_clex_str, DATA_clex_str, INDEX_clex_str. - Changed primary_key_name to a LEX_CSTRING - Renamed String::set_quick() to String::set_buffer_if_not_allocated() to clarify what the function really does. - Rename of protocol function: bool store(const char *from, CHARSET_INFO *cs) to bool store_string_or_null(const char *from, CHARSET_INFO *cs). This was done to both clarify the difference between this 'store' function and also to make it easier to find unoptimal usage of store() calls. - Added Protocol::store(const LEX_CSTRING*, CHARSET_INFO*) - Changed some 'const char*' arrays to instead be of type LEX_CSTRING. - class Item_func_units now used LEX_CSTRING for name. Other things: - Fixed a bug in mysql.cc:construct_prompt() where a wrong escape character in the prompt would cause some part of the prompt to be duplicated. - Fixed a lot of instances where the length of the argument to append is known or easily obtain but was not used. - Removed some not needed 'virtual' definition for functions that was inherited from the parent. I added override to these. - Fixed Ordered_key::print() to preallocate needed buffer. Old code could case memory overruns. - Simplified some loops when adding char * to a String with delimiters.
Diffstat (limited to 'sql/item_vers.h')
-rw-r--r--sql/item_vers.h43
1 files changed, 25 insertions, 18 deletions
diff --git a/sql/item_vers.h b/sql/item_vers.h
index e6cfe652029..177336775c5 100644
--- a/sql/item_vers.h
+++ b/sql/item_vers.h
@@ -46,7 +46,11 @@ public:
max_length= 1;
return FALSE;
}
- virtual const char* func_name() const { return "is_history"; }
+ virtual LEX_CSTRING func_name_cstring() const override
+ {
+ static LEX_CSTRING name= {STRING_WITH_LEN("is_history") };
+ return name;
+ }
virtual void print(String *str, enum_query_type query_type);
Item *get_copy(THD *thd)
{ return get_item_copy<Item_func_history>(thd, this); }
@@ -57,13 +61,11 @@ class Item_func_trt_ts: public Item_datetimefunc
TR_table::field_id_t trt_field;
public:
Item_func_trt_ts(THD *thd, Item* a, TR_table::field_id_t _trt_field);
- const char *func_name() const
+ LEX_CSTRING func_name_cstring() const override
{
- if (trt_field == TR_table::FLD_BEGIN_TS)
- {
- return "trt_begin_ts";
- }
- return "trt_commit_ts";
+ static LEX_CSTRING begin_name= {STRING_WITH_LEN("trt_begin_ts") };
+ static LEX_CSTRING commit_name= {STRING_WITH_LEN("trt_commit_ts") };
+ return (trt_field == TR_table::FLD_BEGIN_TS) ? begin_name : commit_name;
}
bool get_date(THD *thd, MYSQL_TIME *res, date_mode_t fuzzydate);
Item *get_copy(THD *thd)
@@ -84,20 +86,23 @@ public:
Item_func_trt_id(THD *thd, Item* a, TR_table::field_id_t _trt_field, bool _backwards= false);
Item_func_trt_id(THD *thd, Item* a, Item* b, TR_table::field_id_t _trt_field);
- const char *func_name() const
+ LEX_CSTRING func_name_cstring() const override
{
- switch (trt_field)
- {
+ static LEX_CSTRING trx_name= {STRING_WITH_LEN("trt_trx_id") };
+ static LEX_CSTRING commit_name= {STRING_WITH_LEN("trt_commit_id") };
+ static LEX_CSTRING iso_name= {STRING_WITH_LEN("trt_iso_level") };
+
+ switch (trt_field) {
case TR_table::FLD_TRX_ID:
- return "trt_trx_id";
+ return trx_name;
case TR_table::FLD_COMMIT_ID:
- return "trt_commit_id";
+ return commit_name;
case TR_table::FLD_ISO_LEVEL:
- return "trt_iso_level";
+ return iso_name;
default:
DBUG_ASSERT(0);
}
- return NULL;
+ return NULL_clex_str;
}
bool fix_length_and_dec()
@@ -119,9 +124,10 @@ protected:
public:
Item_func_trt_trx_sees(THD *thd, Item* a, Item* b);
- const char *func_name() const
+ LEX_CSTRING func_name_cstring() const override
{
- return "trt_trx_sees";
+ static LEX_CSTRING name= {STRING_WITH_LEN("trt_trx_sees") };
+ return name;
}
longlong val_int();
Item *get_copy(THD *thd)
@@ -137,9 +143,10 @@ public:
{
accept_eq= true;
}
- const char *func_name() const
+ LEX_CSTRING func_name_cstring() const override
{
- return "trt_trx_sees_eq";
+ static LEX_CSTRING name= {STRING_WITH_LEN("trt_trx_sees_eq") };
+ return name;
}
};