diff --git a/sql/sql_string.cc b/sql/sql_string.cc index 5083fb13105..51b2386ae62 100644 --- a/sql/sql_string.cc +++ b/sql/sql_string.cc @@ -97,14 +97,7 @@ bool String::set(longlong num, CHARSET_INFO *cs) if (alloc(l)) return TRUE; - if (cs->snprintf == my_snprintf_8bit) - { - str_length=(uint32) (longlong10_to_str(num,Ptr,-10)-Ptr); - } - else - { - str_length=cs->snprintf(cs,Ptr,l,"%d",num); - } + str_length=(uint32) cs->ll10tostr(cs,Ptr,l,-10,num); str_charset=cs; return FALSE; } @@ -115,14 +108,7 @@ bool String::set(ulonglong num, CHARSET_INFO *cs) if (alloc(l)) return TRUE; - if (cs->snprintf == my_snprintf_8bit) - { - str_length=(uint32) (longlong10_to_str(num,Ptr,10)-Ptr); - } - else - { - str_length=cs->snprintf(cs,Ptr,l,"%d",num); - } + str_length=(uint32) cs->ll10tostr(cs,Ptr,l,10,num); str_charset=cs; return FALSE; } diff --git a/strings/ctype-simple.c b/strings/ctype-simple.c index 7c97c8d23e7..fa1ece20b3e 100644 --- a/strings/ctype-simple.c +++ b/strings/ctype-simple.c @@ -717,22 +717,102 @@ double my_strntod_8bit(CHARSET_INFO *cs __attribute__((unused)), int my_l10tostr_8bit(CHARSET_INFO *cs __attribute__((unused)), char *dst, uint len, int radix, long int val) { - val=radix=len; - dst[0]='\0'; - return 0; -} + char buffer[66]; + register char *p, *e; + long int new_val; + int sl=0; + uint l; + + e = p = &buffer[sizeof(buffer)-1]; + *e='\0'; + + if (radix < 0) + { + if (val < 0) + { + sl = 1; + val = -val; + } + } + + new_val = (long) ((unsigned long int) val / 10); + *--p = '0'+ (char) ((unsigned long int) val - (unsigned long) new_val * 10); + val = new_val; + + while (val != 0) + { + new_val=val/10; + *--p = '0' + (char) (val-new_val*10); + val= new_val; + } + + if (sl) + { + *--p='-'; + } + l=e-p; + l=(l>len)?len:l; + memcpy(dst,p,l); + return (int)l; +} int my_ll10tostr_8bit(CHARSET_INFO *cs __attribute__((unused)), char *dst, uint len, int radix, longlong val) { - val=radix=len; - dst[0]='\0'; - return 0; + char buffer[65]; + register char *p, *e; + long long_val; + int sl=0; + uint l; + + if (radix < 0) + { + if (val < 0) + { + sl=1; + val = -val; + } + } + + e = p = &buffer[sizeof(buffer)-1]; + *p='\0'; + + if (val == 0) + { + *--p='0'; + goto cnv; + } + + while ((ulonglong) val > (ulonglong) LONG_MAX) + { + ulonglong quo=(ulonglong) val/(uint) 10; + uint rem= (uint) (val- quo* (uint) 10); + *--p = '0' + rem; + val= quo; + } + + long_val= (long) val; + while (long_val != 0) + { + long quo= long_val/10; + *--p = '0' + (long_val - quo*10); + long_val= quo; + } + +cnv: + if (sl) + { + *--p='-'; + } + + l=e-p; + l=(l>len)?len:l; + memcpy(dst,p,l); + return (int)(e-p); } - /* ** Compare string against string with wildcard ** 0 if matched diff --git a/strings/ctype-utf8.c b/strings/ctype-utf8.c index 55a887db920..17cc9a6390e 100644 --- a/strings/ctype-utf8.c +++ b/strings/ctype-utf8.c @@ -2910,6 +2910,117 @@ double my_strntod_ucs2(CHARSET_INFO *cs __attribute__((unused)), } +/* + This is a fast version optimized for the case of radix 10 / -10 +*/ + +int my_l10tostr_ucs2(CHARSET_INFO *cs, + char *dst, uint len, int radix, long int val) +{ + char buffer[66]; + register char *p, *db, *de; + long int new_val; + int sl=0; + + p = &buffer[sizeof(buffer)-1]; + *p='\0'; + + if (radix < 0) + { + if (val < 0) + { + sl = 1; + val = -val; + } + } + + new_val = (long) ((unsigned long int) val / 10); + *--p = '0'+ (char) ((unsigned long int) val - (unsigned long) new_val * 10); + val = new_val; + + while (val != 0) + { + new_val=val/10; + *--p = '0' + (char) (val-new_val*10); + val= new_val; + } + + if (sl) + { + *--p='-'; + } + + for ( db=dst, de=dst+len ; (dstwc_mb(cs,(my_wc_t)p[0],dst,de); + if (cnvres>0) + dst+=cnvres; + else + break; + } + return (int) (dst-db); +} + +int my_ll10tostr_ucs2(CHARSET_INFO *cs __attribute__((unused)), + char *dst, uint len, int radix, longlong val) +{ + char buffer[65]; + register char *p, *db, *de; + long long_val; + int sl=0; + + if (radix < 0) + { + if (val < 0) + { + sl=1; + val = -val; + } + } + + p = &buffer[sizeof(buffer)-1]; + *p='\0'; + + if (val == 0) + { + *--p='0'; + goto cnv; + } + + while ((ulonglong) val > (ulonglong) LONG_MAX) + { + ulonglong quo=(ulonglong) val/(uint) 10; + uint rem= (uint) (val- quo* (uint) 10); + *--p = '0' + rem; + val= quo; + } + + long_val= (long) val; + while (long_val != 0) + { + long quo= long_val/10; + *--p = '0' + (long_val - quo*10); + long_val= quo; + } + +cnv: + if (sl) + { + *--p='-'; + } + + for ( db=dst, de=dst+len ; (dstwc_mb(cs,(my_wc_t)p[0],dst,de); + if (cnvres>0) + dst+=cnvres; + else + break; + } + return (int) (dst-db); +} + + CHARSET_INFO my_charset_ucs2 = { 35, /* number */