Commit cf89b487 authored by unknown's avatar unknown

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


sql/sql_string.cc:
  New num->str functions
strings/ctype-simple.c:
  New num->str functions
strings/ctype-utf8.c:
  New num->str functions
parent c873889f
...@@ -97,14 +97,7 @@ bool String::set(longlong num, CHARSET_INFO *cs) ...@@ -97,14 +97,7 @@ bool String::set(longlong num, CHARSET_INFO *cs)
if (alloc(l)) if (alloc(l))
return TRUE; return TRUE;
if (cs->snprintf == my_snprintf_8bit) str_length=(uint32) cs->ll10tostr(cs,Ptr,l,-10,num);
{
str_length=(uint32) (longlong10_to_str(num,Ptr,-10)-Ptr);
}
else
{
str_length=cs->snprintf(cs,Ptr,l,"%d",num);
}
str_charset=cs; str_charset=cs;
return FALSE; return FALSE;
} }
...@@ -115,14 +108,7 @@ bool String::set(ulonglong num, CHARSET_INFO *cs) ...@@ -115,14 +108,7 @@ bool String::set(ulonglong num, CHARSET_INFO *cs)
if (alloc(l)) if (alloc(l))
return TRUE; return TRUE;
if (cs->snprintf == my_snprintf_8bit) str_length=(uint32) cs->ll10tostr(cs,Ptr,l,10,num);
{
str_length=(uint32) (longlong10_to_str(num,Ptr,10)-Ptr);
}
else
{
str_length=cs->snprintf(cs,Ptr,l,"%d",num);
}
str_charset=cs; str_charset=cs;
return FALSE; return FALSE;
} }
......
...@@ -717,22 +717,102 @@ double my_strntod_8bit(CHARSET_INFO *cs __attribute__((unused)), ...@@ -717,22 +717,102 @@ double my_strntod_8bit(CHARSET_INFO *cs __attribute__((unused)),
int my_l10tostr_8bit(CHARSET_INFO *cs __attribute__((unused)), int my_l10tostr_8bit(CHARSET_INFO *cs __attribute__((unused)),
char *dst, uint len, int radix, long int val) char *dst, uint len, int radix, long int val)
{ {
val=radix=len; char buffer[66];
dst[0]='\0'; register char *p, *e;
return 0; 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)), int my_ll10tostr_8bit(CHARSET_INFO *cs __attribute__((unused)),
char *dst, uint len, int radix, longlong val) char *dst, uint len, int radix, longlong val)
{ {
val=radix=len; char buffer[65];
dst[0]='\0'; register char *p, *e;
return 0; 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 ** Compare string against string with wildcard
** 0 if matched ** 0 if matched
......
...@@ -2910,6 +2910,117 @@ double my_strntod_ucs2(CHARSET_INFO *cs __attribute__((unused)), ...@@ -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 = CHARSET_INFO my_charset_ucs2 =
{ {
35, /* number */ 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