mirror of
https://github.com/MariaDB/server.git
synced 2025-07-30 16:24:05 +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:
@ -804,7 +804,7 @@ void vers_select_conds_t::print(String *str, enum_query_type query_type) const
|
||||
DBUG_ASSERT(0);
|
||||
break;
|
||||
case SYSTEM_TIME_ALL:
|
||||
str->append(" FOR SYSTEM_TIME ALL");
|
||||
str->append(STRING_WITH_LEN(" FOR SYSTEM_TIME ALL"));
|
||||
break;
|
||||
}
|
||||
}
|
||||
@ -13477,8 +13477,11 @@ make_join_readinfo(JOIN *join, ulonglong options, uint no_jbuf_after)
|
||||
char buff[256];
|
||||
String str(buff,sizeof(buff),system_charset_info);
|
||||
str.length(0);
|
||||
str.append(tab->table? tab->table->alias.c_ptr() :"<no_table_name>");
|
||||
str.append(" final_pushdown_cond");
|
||||
if (tab->table)
|
||||
str.append(tab->table->alias);
|
||||
else
|
||||
str.append(STRING_WITH_LEN("<no_table_name>"));
|
||||
str.append(STRING_WITH_LEN(" final_pushdown_cond"));
|
||||
print_where(tab->select_cond, str.c_ptr_safe(), QT_ORDINARY););
|
||||
}
|
||||
uint n_top_tables= (uint)(join->join_tab_ranges.head()->end -
|
||||
@ -27733,13 +27736,13 @@ Index_hint::print(THD *thd, String *str)
|
||||
case INDEX_HINT_USE: str->append(STRING_WITH_LEN("USE INDEX")); break;
|
||||
case INDEX_HINT_FORCE: str->append(STRING_WITH_LEN("FORCE INDEX")); break;
|
||||
}
|
||||
str->append (STRING_WITH_LEN(" ("));
|
||||
str->append(STRING_WITH_LEN(" ("));
|
||||
if (key_name.length)
|
||||
{
|
||||
if (thd && !system_charset_info->strnncoll(
|
||||
(const uchar *)key_name.str, key_name.length,
|
||||
(const uchar *)primary_key_name,
|
||||
strlen(primary_key_name)))
|
||||
(const uchar *)primary_key_name.str,
|
||||
primary_key_name.length))
|
||||
str->append(primary_key_name);
|
||||
else
|
||||
append_identifier(thd, str, &key_name);
|
||||
@ -27897,8 +27900,8 @@ void TABLE_LIST::print(THD *thd, table_map eliminated_tables, String *str,
|
||||
|
||||
while ((hint= it++))
|
||||
{
|
||||
str->append (STRING_WITH_LEN(" "));
|
||||
hint->print (thd, str);
|
||||
str->append(' ');
|
||||
hint->print(thd, str);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -27920,21 +27923,21 @@ void st_select_lex::print(THD *thd, String *str, enum_query_type query_type)
|
||||
thd->lex->all_selects_list->link_next &&
|
||||
select_number != FAKE_SELECT_LEX_ID)
|
||||
{
|
||||
str->append("/* select#");
|
||||
str->append(STRING_WITH_LEN("/* select#"));
|
||||
str->append_ulonglong(select_number);
|
||||
if (thd->lex->describe & DESCRIBE_EXTENDED2)
|
||||
{
|
||||
str->append("/");
|
||||
str->append('/');
|
||||
str->append_ulonglong(nest_level);
|
||||
|
||||
if (master_unit()->fake_select_lex &&
|
||||
master_unit()->first_select() == this)
|
||||
{
|
||||
str->append(" Filter Select: ");
|
||||
str->append(STRING_WITH_LEN(" Filter Select: "));
|
||||
master_unit()->fake_select_lex->print(thd, str, query_type);
|
||||
}
|
||||
}
|
||||
str->append(" */ ");
|
||||
str->append(STRING_WITH_LEN(" */ "));
|
||||
}
|
||||
|
||||
str->append(STRING_WITH_LEN("select "));
|
||||
@ -28034,7 +28037,7 @@ void st_select_lex::print(THD *thd, String *str, enum_query_type query_type)
|
||||
if (cur_where)
|
||||
cur_where->print(str, query_type);
|
||||
else
|
||||
str->append(cond_value != Item::COND_FALSE ? "1" : "0");
|
||||
str->append(cond_value != Item::COND_FALSE ? '1' : '0');
|
||||
}
|
||||
|
||||
// group by & olap
|
||||
@ -28066,7 +28069,7 @@ void st_select_lex::print(THD *thd, String *str, enum_query_type query_type)
|
||||
if (cur_having)
|
||||
cur_having->print(str, query_type);
|
||||
else
|
||||
str->append(having_value != Item::COND_FALSE ? "1" : "0");
|
||||
str->append(having_value != Item::COND_FALSE ? '1' : '0');
|
||||
}
|
||||
|
||||
if (order_list.elements)
|
||||
@ -28080,12 +28083,11 @@ void st_select_lex::print(THD *thd, String *str, enum_query_type query_type)
|
||||
|
||||
// lock type
|
||||
if (select_lock == select_lock_type::IN_SHARE_MODE)
|
||||
str->append(" lock in share mode");
|
||||
str->append(STRING_WITH_LEN(" lock in share mode"));
|
||||
else if (select_lock == select_lock_type::FOR_UPDATE)
|
||||
str->append(" for update");
|
||||
|
||||
str->append(STRING_WITH_LEN(" for update"));
|
||||
if (unlikely(skip_locked))
|
||||
str->append(" skip locked");
|
||||
str->append(STRING_WITH_LEN(" skip locked"));
|
||||
|
||||
// PROCEDURE unsupported here
|
||||
}
|
||||
|
Reference in New Issue
Block a user