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

String::release and String::reset methods

Rename reassociate to reset and create an inverse method release.
Method names are chosen to match std::unique_ptr methods.
This commit is contained in:
Sergei Golubchik
2015-08-16 22:22:52 +02:00
parent 4569a895f9
commit e238d6c513
2 changed files with 15 additions and 9 deletions

View File

@ -4583,8 +4583,7 @@ String *Item_func_dyncol_create::val_str(String *str)
char *ptr; char *ptr;
size_t length, alloc_length; size_t length, alloc_length;
dynstr_reassociate(&col, &ptr, &length, &alloc_length); dynstr_reassociate(&col, &ptr, &length, &alloc_length);
str_value.reassociate(ptr, (uint32) length, (uint32) alloc_length, str_value.reset(ptr, length, alloc_length, &my_charset_bin);
&my_charset_bin);
res= &str_value; res= &str_value;
null_value= FALSE; null_value= FALSE;
} }
@ -4676,8 +4675,7 @@ String *Item_func_dyncol_json::val_str(String *str)
char *ptr; char *ptr;
size_t length, alloc_length; size_t length, alloc_length;
dynstr_reassociate(&json, &ptr, &length, &alloc_length); dynstr_reassociate(&json, &ptr, &length, &alloc_length);
str->reassociate(ptr, (uint32) length, (uint32) alloc_length, str->reset(ptr, length, alloc_length, &my_charset_utf8_general_ci);
&my_charset_utf8_general_ci);
null_value= FALSE; null_value= FALSE;
} }
return str; return str;
@ -4725,8 +4723,7 @@ String *Item_func_dyncol_add::val_str(String *str)
char *ptr; char *ptr;
size_t length, alloc_length; size_t length, alloc_length;
dynstr_reassociate(&col, &ptr, &length, &alloc_length); dynstr_reassociate(&col, &ptr, &length, &alloc_length);
str->reassociate(ptr, (uint32) length, (uint32) alloc_length, str->reset(ptr, length, alloc_length, &my_charset_bin);
&my_charset_bin);
null_value= FALSE; null_value= FALSE;
} }

View File

@ -257,9 +257,9 @@ public:
bool set(ulonglong num, CHARSET_INFO *cs) { return set_int((longlong)num, true, cs); } bool set(ulonglong num, CHARSET_INFO *cs) { return set_int((longlong)num, true, cs); }
bool set_real(double num,uint decimals, CHARSET_INFO *cs); bool set_real(double num,uint decimals, CHARSET_INFO *cs);
/* Move handling of buffer from some other object to String */ /* Take over handling of buffer from some other object */
void reassociate(char *ptr_arg, uint32 length_arg, uint32 alloced_length_arg, void reset(char *ptr_arg, uint32 length_arg, uint32 alloced_length_arg,
CHARSET_INFO *cs) CHARSET_INFO *cs)
{ {
free(); free();
Ptr= ptr_arg; Ptr= ptr_arg;
@ -269,6 +269,15 @@ public:
alloced= ptr_arg != 0; alloced= ptr_arg != 0;
} }
/* Forget about the buffer, let some other object handle it */
char *release()
{
char *old= Ptr;
Ptr=0; str_length= Alloced_length= extra_alloc= 0;
alloced= thread_specific= 0;
return old;
}
/* /*
PMG 2004.11.12 PMG 2004.11.12
This is a method that works the same as perl's "chop". It simply This is a method that works the same as perl's "chop". It simply