From 949d10bea27050970bf04aeaac4217e24997ce95 Mon Sep 17 00:00:00 2001 From: Monty Date: Thu, 3 Sep 2020 20:27:12 +0300 Subject: Don't reset StringBuffers in loops when not needed - Moved out creating StringBuffers in loops and instead create them outside and just reset the buffer if it was not allocated (to avoid a possible malloc/free for every entry) Other things related to set_buffer_if_not_allocated() - Changed Valuebuffer to not call set_buffer_if_not_allocated() when it is created. - Fixed geometry functions to reset string length before calling String::reserve(). This is because one should not access length() of an undefined. - Added Item_func_conv_charset::save_in_field() as the item is using str_value to store cached values, which conflicts with Item::save_str_in_field(). - Changed Item_proc_string to not store the string value in sql_string as this clashes with Item::save_str_in_field(). - Locally store value of full_name_cstring() in analyse::end_of_records() as Item::save_str_in_field() may overwrite it. - Marked some strings as set_thread_specific() - Added String::free_buffer() to be used internally in String functions to just free the buffer but not reset other String values. - Fixed uses_buffer_owned_by() to check for allocated length instead of strlength, which could be marked MEM_UNDEFINED(). --- sql/sql_string.cc | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) (limited to 'sql/sql_string.cc') diff --git a/sql/sql_string.cc b/sql/sql_string.cc index aca9ede9000..c9117451374 100644 --- a/sql/sql_string.cc +++ b/sql/sql_string.cc @@ -40,7 +40,7 @@ bool Binary_string::real_alloc(size_t length) str_length=0; if (Alloced_length < arg_length) { - free(); + free_buffer(); if (!(Ptr=(char*) my_malloc(STRING_PSI_MEMORY_KEY, arg_length,MYF(MY_WME | (thread_specific ? MY_THREAD_SPECIFIC : 0))))) @@ -1112,7 +1112,8 @@ uint String_copier::well_formed_copy(CHARSET_INFO *to_cs, char *to, size_t to_length, CHARSET_INFO *from_cs, - const char *from, size_t from_length, size_t nchars) + const char *from, size_t from_length, + size_t nchars) { if ((to_cs == &my_charset_bin) || (from_cs == &my_charset_bin) || -- cgit v1.2.1