Skip to content

Commit

Permalink
String::release and String::reset methods
Browse files Browse the repository at this point in the history
Rename reassociate to reset and create an inverse method release.
Method names are chosen to match std::unique_ptr methods.
  • Loading branch information
vuvova committed Sep 4, 2015
1 parent 4569a89 commit e238d6c
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 9 deletions.
9 changes: 3 additions & 6 deletions sql/item_strfunc.cc
Original file line number Diff line number Diff line change
Expand Up @@ -4583,8 +4583,7 @@ String *Item_func_dyncol_create::val_str(String *str)
char *ptr;
size_t length, alloc_length;
dynstr_reassociate(&col, &ptr, &length, &alloc_length);
str_value.reassociate(ptr, (uint32) length, (uint32) alloc_length,
&my_charset_bin);
str_value.reset(ptr, length, alloc_length, &my_charset_bin);
res= &str_value;
null_value= FALSE;
}
Expand Down Expand Up @@ -4676,8 +4675,7 @@ String *Item_func_dyncol_json::val_str(String *str)
char *ptr;
size_t length, alloc_length;
dynstr_reassociate(&json, &ptr, &length, &alloc_length);
str->reassociate(ptr, (uint32) length, (uint32) alloc_length,
&my_charset_utf8_general_ci);
str->reset(ptr, length, alloc_length, &my_charset_utf8_general_ci);
null_value= FALSE;
}
return str;
Expand Down Expand Up @@ -4725,8 +4723,7 @@ String *Item_func_dyncol_add::val_str(String *str)
char *ptr;
size_t length, alloc_length;
dynstr_reassociate(&col, &ptr, &length, &alloc_length);
str->reassociate(ptr, (uint32) length, (uint32) alloc_length,
&my_charset_bin);
str->reset(ptr, length, alloc_length, &my_charset_bin);
null_value= FALSE;
}

Expand Down
15 changes: 12 additions & 3 deletions sql/sql_string.h
Original file line number Diff line number Diff line change
Expand Up @@ -257,9 +257,9 @@ class String
bool set(ulonglong num, CHARSET_INFO *cs) { return set_int((longlong)num, true, cs); }
bool set_real(double num,uint decimals, CHARSET_INFO *cs);

/* Move handling of buffer from some other object to String */
void reassociate(char *ptr_arg, uint32 length_arg, uint32 alloced_length_arg,
CHARSET_INFO *cs)
/* Take over handling of buffer from some other object */
void reset(char *ptr_arg, uint32 length_arg, uint32 alloced_length_arg,
CHARSET_INFO *cs)
{
free();
Ptr= ptr_arg;
Expand All @@ -269,6 +269,15 @@ class String
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
This is a method that works the same as perl's "chop". It simply
Expand Down

0 comments on commit e238d6c

Please sign in to comment.