1
0
mirror of https://github.com/MariaDB/server.git synced 2025-07-29 05:21:33 +03:00

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.
This commit is contained in:
Monty
2020-08-12 20:29:55 +03:00
committed by Sergei Golubchik
parent b3bc02f923
commit b6ff139aa3
113 changed files with 3543 additions and 1764 deletions

View File

@ -3193,7 +3193,7 @@ public:
aggregate_numeric_attributes_decimal(items, nitems,
(unsigned_flag= unsigned_arg));
}
bool aggregate_attributes_string(const char *func_name,
bool aggregate_attributes_string(const LEX_CSTRING &func_name,
Item **item, uint nitems);
void aggregate_attributes_temporal(uint int_part_length,
Item **item, uint nitems)
@ -3201,10 +3201,11 @@ public:
fix_attributes_temporal(int_part_length, find_max_decimals(item, nitems));
}
bool agg_item_collations(DTCollation &c, const char *name,
bool agg_item_collations(DTCollation &c, const LEX_CSTRING &name,
Item **items, uint nitems,
uint flags, int item_sep);
bool agg_item_set_converter(const DTCollation &coll, const char *fname,
bool agg_item_set_converter(const DTCollation &coll,
const LEX_CSTRING &name,
Item **args, uint nargs,
uint flags, int item_sep);
@ -3236,7 +3237,7 @@ public:
agg_item_charsets(coll, fname, &args[2], 2, flags, 3)
*/
bool agg_arg_charsets(DTCollation &c, const char *func_name,
bool agg_arg_charsets(DTCollation &c, const LEX_CSTRING &func_name,
Item **items, uint nitems,
uint flags, int item_sep)
{
@ -3249,7 +3250,8 @@ public:
- convert to @@character_set_connection if all arguments are numbers
- allow DERIVATION_NONE
*/
bool agg_arg_charsets_for_string_result(DTCollation &c, const char *func_name,
bool agg_arg_charsets_for_string_result(DTCollation &c,
const LEX_CSTRING &func_name,
Item **items, uint nitems,
int item_sep)
{
@ -3265,7 +3267,7 @@ public:
- disallow DERIVATION_NONE
*/
bool agg_arg_charsets_for_string_result_with_comparison(DTCollation &c,
const char *func_name,
const LEX_CSTRING &func_name,
Item **items,
uint nitems,
int item_sep)
@ -3283,7 +3285,7 @@ public:
- don't allow DERIVATION_NONE
*/
bool agg_arg_charsets_for_comparison(DTCollation &c,
const char *func_name,
const LEX_CSTRING &func_name,
Item **items, uint nitems,
int item_sep)
{
@ -3589,7 +3591,7 @@ protected:
longlong value,
const SORT_FIELD_ATTR *sort_field) const;
bool Item_func_or_sum_illegal_param(const char *name) const;
bool Item_func_or_sum_illegal_param(const LEX_CSTRING &name) const;
bool Item_func_or_sum_illegal_param(const Item_func_or_sum *) const;
bool check_null(const Item *item, st_value *value) const;
bool Item_send_str(Item *item, Protocol *protocol, st_value *buf) const;
@ -4190,7 +4192,7 @@ public:
virtual bool Item_eq_value(THD *thd, const Type_cmp_attributes *attr,
Item *a, Item *b) const= 0;
virtual bool Item_hybrid_func_fix_attributes(THD *thd,
const char *name,
const LEX_CSTRING &name,
Type_handler_hybrid_field_type *,
Type_all_attributes *atrr,
Item **items,
@ -4523,7 +4525,7 @@ public:
}
bool set_comparator_func(THD *thd, Arg_comparator *cmp) const override;
bool Item_hybrid_func_fix_attributes(THD *thd,
const char *name,
const LEX_CSTRING &name,
Type_handler_hybrid_field_type *,
Type_all_attributes *atrr,
Item **items, uint nitems)
@ -4820,7 +4822,7 @@ public:
const override;
bool set_comparator_func(THD *thd, Arg_comparator *cmp) const override;
bool Item_hybrid_func_fix_attributes(THD *thd,
const char *name,
const LEX_CSTRING &name,
Type_handler_hybrid_field_type *,
Type_all_attributes *atrr,
Item **items, uint nitems)
@ -4956,7 +4958,7 @@ public:
Item_cache *Item_get_cache(THD *thd, const Item *item) const override;
bool set_comparator_func(THD *thd, Arg_comparator *cmp) const override;
bool Item_hybrid_func_fix_attributes(THD *thd,
const char *name,
const LEX_CSTRING &name,
Type_handler_hybrid_field_type *,
Type_all_attributes *atrr,
Item **items, uint nitems)
@ -5190,7 +5192,7 @@ public:
Item_cache *Item_get_cache(THD *thd, const Item *item) const override;
bool set_comparator_func(THD *thd, Arg_comparator *cmp) const override;
bool Item_hybrid_func_fix_attributes(THD *thd,
const char *name,
const LEX_CSTRING &name,
Type_handler_hybrid_field_type *,
Type_all_attributes *atrr,
Item **items, uint nitems) const override;
@ -5454,7 +5456,7 @@ public:
Item_cache *Item_get_cache(THD *thd, const Item *item) const override;
bool set_comparator_func(THD *thd, Arg_comparator *cmp) const override;
bool Item_hybrid_func_fix_attributes(THD *thd,
const char *name,
const LEX_CSTRING &name,
Type_handler_hybrid_field_type *,
Type_all_attributes *atrr,
Item **items, uint nitems) const
@ -6135,7 +6137,7 @@ public:
Item_cache *Item_get_cache(THD *thd, const Item *item) const override;
longlong Item_val_int_unsigned_typecast(Item *item) const override;
bool Item_hybrid_func_fix_attributes(THD *thd,
const char *name,
const LEX_CSTRING &name,
Type_handler_hybrid_field_type *,
Type_all_attributes *atrr,
Item **items, uint nitems)
@ -6329,7 +6331,7 @@ public:
bool Item_func_round_fix_length_and_dec(Item_func_round *) const override;
bool Item_func_int_val_fix_length_and_dec(Item_func_int_val*) const override;
bool Item_hybrid_func_fix_attributes(THD *thd,
const char *name,
const LEX_CSTRING &name,
Type_handler_hybrid_field_type *,
Type_all_attributes *atrr,
Item **items, uint nitems) const
@ -6470,7 +6472,7 @@ public:
const override;
bool Item_func_round_fix_length_and_dec(Item_func_round *) const override;
bool Item_hybrid_func_fix_attributes(THD *thd,
const char *name,
const LEX_CSTRING &name,
Type_handler_hybrid_field_type *,
Type_all_attributes *atrr,
Item **items, uint nitems)
@ -6634,7 +6636,7 @@ public:
my_decimal *) const override;
bool set_comparator_func(THD *thd, Arg_comparator *cmp) const override;
bool Item_hybrid_func_fix_attributes(THD *thd,
const char *name,
const LEX_CSTRING &name,
Type_handler_hybrid_field_type *,
Type_all_attributes *atrr,
Item **items, uint nitems)
@ -7121,7 +7123,7 @@ public:
const Column_definition &def,
const handler *file) const override;
bool Item_hybrid_func_fix_attributes(THD *thd,
const char *name,
const LEX_CSTRING &name,
Type_handler_hybrid_field_type *,
Type_all_attributes *atrr,
Item **items, uint nitems) const
@ -7253,7 +7255,7 @@ public:
bool Item_func_int_val_fix_length_and_dec(Item_func_int_val*) const override;
uint32 max_display_length_for_field(const Conv_source &src) const override;
bool Item_hybrid_func_fix_attributes(THD *thd,
const char *name,
const LEX_CSTRING &name,
Type_handler_hybrid_field_type *,
Type_all_attributes *atrr,
Item **items, uint nitems)
@ -7456,13 +7458,14 @@ public:
return (m_type_handler= Type_handler::get_handler_by_real_type(type));
}
bool aggregate_for_comparison(const Type_handler *other);
bool aggregate_for_comparison(const char *funcname,
bool aggregate_for_comparison(const LEX_CSTRING &funcname,
Item **items, uint nitems,
bool treat_int_to_uint_as_decimal);
bool aggregate_for_result(const Type_handler *other);
bool aggregate_for_result(const char *funcname,
bool aggregate_for_result(const LEX_CSTRING &funcname,
Item **item, uint nitems, bool treat_bit_as_number);
bool aggregate_for_min_max(const char *funcname, Item **item, uint nitems);
bool aggregate_for_min_max(const LEX_CSTRING &funcname, Item **item,
uint nitems);
bool aggregate_for_num_op(const class Type_aggregator *aggregator,
const Type_handler *h0, const Type_handler *h1);