diff options
author | unknown <bar@bar.intranet.mysql.r18.ru> | 2004-05-25 15:54:03 +0500 |
---|---|---|
committer | unknown <bar@bar.intranet.mysql.r18.ru> | 2004-05-25 15:54:03 +0500 |
commit | 9983aed876568891e07fbdeed402c9c7f1320c03 (patch) | |
tree | 5b89afdba70f8480882113658142e4dfd12afac7 /sql/sql_string.cc | |
parent | f80e9e042ee33e1debdac1e46992470e495921c9 (diff) | |
download | mariadb-git-9983aed876568891e07fbdeed402c9c7f1320c03.tar.gz |
1. Some optimization when conversion is not needed.
2. One now must pass length argument into append(const char *str, uint length),
length is not calculated internally anymore.
Diffstat (limited to 'sql/sql_string.cc')
-rw-r--r-- | sql/sql_string.cc | 43 |
1 files changed, 28 insertions, 15 deletions
diff --git a/sql/sql_string.cc b/sql/sql_string.cc index fb2d1661357..b60aee2b5df 100644 --- a/sql/sql_string.cc +++ b/sql/sql_string.cc @@ -416,16 +416,18 @@ bool String::append(const String &s) /* - Append a latin1 string to the a string of the current character set + Append an ASCII string to the a string of the current character set */ - bool String::append(const char *s,uint32 arg_length) { - if (!arg_length) // Default argument - if (!(arg_length= (uint32) strlen(s))) - return FALSE; - if (str_charset->mbmaxlen > 1) + if (!arg_length) + return FALSE; + + /* + For an ASCII incompatible string, e.g. UCS-2, we need to convert + */ + if (str_charset->mbminlen > 1) { uint32 add_length=arg_length * str_charset->mbmaxlen; if (realloc(str_length+ add_length)) @@ -434,6 +436,10 @@ bool String::append(const char *s,uint32 arg_length) s, arg_length, &my_charset_latin1); return FALSE; } + + /* + For an ASCII compatinble string we can just append. + */ if (realloc(str_length+arg_length)) return TRUE; memcpy(Ptr+str_length,s,arg_length); @@ -443,29 +449,36 @@ bool String::append(const char *s,uint32 arg_length) /* + Append a 0-terminated ASCII string +*/ + +bool String::append(const char *s) +{ + return append(s, strlen(s)); +} + + +/* Append a string in the given charset to the string with character set recoding */ - bool String::append(const char *s,uint32 arg_length, CHARSET_INFO *cs) { uint32 dummy_offset; - uint32 add_length; - - if (!arg_length && !(arg_length= (uint32)strlen(s))) - return FALSE; - - add_length= arg_length * str_charset->mbmaxlen; - if (realloc(str_length + add_length)) - return TRUE; + if (needs_conversion(arg_length, cs, str_charset, &dummy_offset)) { + uint32 add_length= arg_length / cs->mbminlen * str_charset->mbmaxlen; + if (realloc(str_length + add_length)) + return TRUE; str_length+= copy_and_convert(Ptr+str_length, add_length, str_charset, s, arg_length, cs); } else { + if (realloc(str_length + arg_length)) + return TRUE; memcpy(Ptr + str_length, s, arg_length); str_length+= arg_length; } |