Commit e238d6c5 authored by Sergei Golubchik's avatar Sergei Golubchik

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.
parent 4569a895
...@@ -4583,8 +4583,7 @@ String *Item_func_dyncol_create::val_str(String *str) ...@@ -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) ...@@ -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) ...@@ -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;
} }
......
...@@ -257,8 +257,8 @@ class String ...@@ -257,8 +257,8 @@ class String
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();
...@@ -269,6 +269,15 @@ class String ...@@ -269,6 +269,15 @@ class String
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
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment