Commit 2204f764 authored by bar@bar.mysql.r18.ru's avatar bar@bar.mysql.r18.ru

sql/sql_string.cc@1.39

    New num->str functions
strings/ctype-simple.c@1.16
    New num->str functions
strings/ctype-utf8.c@1.18
    New num->str functions
parent a345447a
......@@ -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;
}
......
......@@ -717,20 +717,100 @@ 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);
}
/*
......
......@@ -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 ; (dst<de) && *p ; p++)
{
int cnvres=cs->wc_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 ; (dst<de) && *p ; p++)
{
int cnvres=cs->wc_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 */
......
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