Additional cleanup and optimization of the printf function. (CVS 2587)

FossilOrigin-Name: 240bb049001b0d1419d72b6ef909236e12bd5949
This commit is contained in:
drh 2005-08-13 13:39:02 +00:00
parent 557cc60f4d
commit 3e9aeec03f
3 changed files with 23 additions and 20 deletions

View File

@ -1,5 +1,5 @@
C Add\sthe\s"!"\sflag\sto\sthe\s"%g"\smprintf\sconversion\sparameter\sto\sforce\sa\ndecimal\spoint.\s\sThis\sprevents\sfloating\spoint\svalues\sfrom\sappearing\sas\nintegers.\s\sUse\sthis\sflag\swhen\sconverting\sfloating\spoint\sto\stext.\nTicket\s#1362.\s(CVS\s2586)
D 2005-08-13T12:59:15
C Additional\scleanup\sand\soptimization\sof\sthe\sprintf\sfunction.\s(CVS\s2587)
D 2005-08-13T13:39:03
F Makefile.in 22ea9c0fe748f591712d8fe3c6d972c6c173a165
F Makefile.linux-gcc 06be33b2a9ad4f005a5f42b22c4a19dab3cbb5c7
F README 9c4e2d6706bdcc3efdd773ce752a8cdab4f90028
@ -60,7 +60,7 @@ F src/pager.h 0d9153d6269d60d04af3dd84a0cc0a96253cf4a4
F src/parse.y d57cdd2adc0923762b40314f08683c836a2e0c90
F src/pragma.c 59ab7073465a11a531af2796e0385727194accb8
F src/prepare.c fa0f6068d9b8ec6d5c419c65d4d8ff747d49c5c6
F src/printf.c d1fa64c696bc05f50471a960bc68cd9b6e861823
F src/printf.c e63e8aa8fc8a54128ccef27e8dbe1a3c60b4e37e
F src/random.c 90adff4e73a3b249eb4f1fc2a6ff9cf78c7233a4
F src/select.c c611471052773b94af771693686bd5bcdbbb0dba
F src/shell.c 86c16f0d534aa51cc82cf9f66903d4eb681580e7
@ -291,7 +291,7 @@ F www/tclsqlite.tcl 3df553505b6efcad08f91e9b975deb2e6c9bb955
F www/vdbe.tcl 87a31ace769f20d3627a64fa1fade7fed47b90d0
F www/version3.tcl a99cf5f6d8bd4d5537584a2b342f0fb9fa601d8b
F www/whentouse.tcl 528299b8316726dbcc5548e9aa0648c8b1bd055b
P 4f47c3c884e38b810450b6127ab33c7b86e6743c
R b3c296ac5d6a7b19a3b058edd9a64bc2
P 4b98dace6b90abf4a6fe1cd51e6392fd213358c4
R 00f1187489ef9968d304d68c4469fe37
U drh
Z faea32e5bc1b77c04bb69a0132002ae9
Z 64274af75cd150ac18f1611e8aab4ae7

View File

@ -1 +1 @@
4b98dace6b90abf4a6fe1cd51e6392fd213358c4
240bb049001b0d1419d72b6ef909236e12bd5949

View File

@ -214,6 +214,7 @@ static int vxprintf(
etByte flag_zeropad; /* True if field width constant starts with zero */
etByte flag_long; /* True if "l" flag is present */
etByte flag_longlong; /* True if the "ll" flag is present */
etByte done; /* Loop termination flag */
UINT64_TYPE longvalue; /* Value for integer types */
LONGDOUBLE_TYPE realvalue; /* Value for real types */
const et_info *infop; /* Pointer to the appropriate info structure */
@ -256,17 +257,18 @@ static int vxprintf(
/* Find out what flags are present */
flag_leftjustify = flag_plussign = flag_blanksign =
flag_alternateform = flag_altform2 = flag_zeropad = 0;
done = 0;
do{
switch( c ){
case '-': flag_leftjustify = 1; c = 0; break;
case '+': flag_plussign = 1; c = 0; break;
case ' ': flag_blanksign = 1; c = 0; break;
case '#': flag_alternateform = 1; c = 0; break;
case '!': flag_altform2 = 1; c = 0; break;
case '0': flag_zeropad = 1; c = 0; break;
default: break;
case '-': flag_leftjustify = 1; break;
case '+': flag_plussign = 1; break;
case ' ': flag_blanksign = 1; break;
case '#': flag_alternateform = 1; break;
case '!': flag_altform2 = 1; break;
case '0': flag_zeropad = 1; break;
default: done = 1; break;
}
}while( c==0 && (c=(*++fmt))!=0 );
}while( !done && (c=(*++fmt))!=0 );
/* Get the field width */
width = 0;
if( c=='*' ){
@ -338,6 +340,7 @@ static int vxprintf(
** At this point, variables are initialized as follows:
**
** flag_alternateform TRUE if a '#' is present.
** flag_altform2 TRUE if a '!' is present.
** flag_plussign TRUE if a '+' is present.
** flag_leftjustify TRUE if a '-' is present or if the
** field width was negative.
@ -425,8 +428,7 @@ static int vxprintf(
else if( flag_blanksign ) prefix = ' ';
else prefix = 0;
}
if( infop->type==etGENERIC && precision>0 ) precision--;
rounder = 0.0;
if( xtype==etGENERIC && precision>0 ) precision--;
#if 0
/* Rounding works like BSD when the constant 0.4999 is used. Wierd! */
for(idx=precision, rounder=0.4999; idx>0; idx--, rounder*=0.1);
@ -434,7 +436,7 @@ static int vxprintf(
/* It makes more sense to use 0.5 */
for(idx=precision, rounder=0.5; idx>0; idx--, rounder*=0.1);
#endif
if( infop->type==etFLOAT ) realvalue += rounder;
if( xtype==etFLOAT ) realvalue += rounder;
/* Normalize realvalue to within 10.0 > realvalue >= 1.0 */
exp = 0;
if( realvalue>0.0 ){
@ -510,8 +512,9 @@ static int vxprintf(
}
/* Remove trailing zeros and the "." if no digits follow the "." */
if( flag_rtz && flag_dp ){
while( bufpt>buf && bufpt[-1]=='0' ) *(--bufpt) = 0;
if( bufpt>buf && bufpt[-1]=='.' ){
while( bufpt[-1]=='0' ) *(--bufpt) = 0;
assert( bufpt>buf );
if( bufpt[-1]=='.' ){
if( flag_altform2 ){
*(bufpt++) = '0';
}else{