mirror of
https://sourceware.org/git/glibc.git
synced 2025-08-07 06:43:00 +03:00
* stdio-common/printf_fp.c (___printf_fp): Cleanups and minor
optimization.
This commit is contained in:
@@ -1,5 +1,8 @@
|
|||||||
2007-02-19 Ulrich Drepper <drepper@redhat.com>
|
2007-02-19 Ulrich Drepper <drepper@redhat.com>
|
||||||
|
|
||||||
|
* stdio-common/printf_fp.c (___printf_fp): Cleanups and minor
|
||||||
|
optimization.
|
||||||
|
|
||||||
* stdio-common/vfscanf.c: Small cleanups throughout.
|
* stdio-common/vfscanf.c: Small cleanups throughout.
|
||||||
|
|
||||||
2007-02-18 Ulrich Drepper <drepper@redhat.com>
|
2007-02-18 Ulrich Drepper <drepper@redhat.com>
|
||||||
|
@@ -1,6 +1,6 @@
|
|||||||
/* Floating point output for `printf'.
|
/* Floating point output for `printf'.
|
||||||
Copyright (C) 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2006
|
Copyright (C) 1995-2003, 2006, 2007 Free Software Foundation, Inc.
|
||||||
Free Software Foundation, Inc.
|
|
||||||
This file is part of the GNU C Library.
|
This file is part of the GNU C Library.
|
||||||
Written by Ulrich Drepper <drepper@gnu.ai.mit.edu>, 1995.
|
Written by Ulrich Drepper <drepper@gnu.ai.mit.edu>, 1995.
|
||||||
|
|
||||||
@@ -811,12 +811,14 @@ ___printf_fp (FILE *fp,
|
|||||||
int chars_needed;
|
int chars_needed;
|
||||||
int expscale;
|
int expscale;
|
||||||
int intdig_max, intdig_no = 0;
|
int intdig_max, intdig_no = 0;
|
||||||
int fracdig_min, fracdig_max, fracdig_no = 0;
|
int fracdig_min;
|
||||||
|
int fracdig_max;
|
||||||
int dig_max;
|
int dig_max;
|
||||||
int significant;
|
int significant;
|
||||||
int ngroups = 0;
|
int ngroups = 0;
|
||||||
|
char spec = _tolower (info->spec);
|
||||||
|
|
||||||
if (_tolower (info->spec) == 'e')
|
if (spec == 'e')
|
||||||
{
|
{
|
||||||
type = info->spec;
|
type = info->spec;
|
||||||
intdig_max = 1;
|
intdig_max = 1;
|
||||||
@@ -826,7 +828,7 @@ ___printf_fp (FILE *fp,
|
|||||||
dig_max = INT_MAX; /* Unlimited. */
|
dig_max = INT_MAX; /* Unlimited. */
|
||||||
significant = 1; /* Does not matter here. */
|
significant = 1; /* Does not matter here. */
|
||||||
}
|
}
|
||||||
else if (_tolower (info->spec) == 'f')
|
else if (spec == 'f')
|
||||||
{
|
{
|
||||||
type = 'f';
|
type = 'f';
|
||||||
fracdig_min = fracdig_max = info->prec < 0 ? 6 : info->prec;
|
fracdig_min = fracdig_max = info->prec < 0 ? 6 : info->prec;
|
||||||
@@ -887,7 +889,7 @@ ___printf_fp (FILE *fp,
|
|||||||
other output. If the amount of memory we have to allocate is too
|
other output. If the amount of memory we have to allocate is too
|
||||||
large use `malloc' instead of `alloca'. */
|
large use `malloc' instead of `alloca'. */
|
||||||
buffer_malloced = ! __libc_use_alloca (chars_needed * 2 * sizeof (wchar_t));
|
buffer_malloced = ! __libc_use_alloca (chars_needed * 2 * sizeof (wchar_t));
|
||||||
if (buffer_malloced)
|
if (__builtin_expect (buffer_malloced, 0))
|
||||||
{
|
{
|
||||||
wbuffer = (wchar_t *) malloc ((2 + chars_needed) * sizeof (wchar_t));
|
wbuffer = (wchar_t *) malloc ((2 + chars_needed) * sizeof (wchar_t));
|
||||||
if (wbuffer == NULL)
|
if (wbuffer == NULL)
|
||||||
@@ -923,6 +925,7 @@ ___printf_fp (FILE *fp,
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* Generate the needed number of fractional digits. */
|
/* Generate the needed number of fractional digits. */
|
||||||
|
int fracdig_no = 0;
|
||||||
while (fracdig_no < fracdig_min
|
while (fracdig_no < fracdig_min
|
||||||
|| (fracdig_no < fracdig_max && (fracsize > 1 || frac[0] != 0)))
|
|| (fracdig_no < fracdig_max && (fracsize > 1 || frac[0] != 0)))
|
||||||
{
|
{
|
||||||
@@ -972,7 +975,7 @@ ___printf_fp (FILE *fp,
|
|||||||
/* Process fractional digits. Terminate if not rounded or
|
/* Process fractional digits. Terminate if not rounded or
|
||||||
radix character is reached. */
|
radix character is reached. */
|
||||||
while (*--wtp != decimalwc && *wtp == L'9')
|
while (*--wtp != decimalwc && *wtp == L'9')
|
||||||
*wtp = '0';
|
*wtp = L'0';
|
||||||
if (*wtp != decimalwc)
|
if (*wtp != decimalwc)
|
||||||
/* Round up. */
|
/* Round up. */
|
||||||
(*wtp)++;
|
(*wtp)++;
|
||||||
|
@@ -52,18 +52,19 @@
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
/* Those are flags in the conversion format. */
|
/* Those are flags in the conversion format. */
|
||||||
#define LONG 0x001 /* l: long or double */
|
#define LONG 0x0001 /* l: long or double */
|
||||||
#define LONGDBL 0x002 /* L: long long or long double */
|
#define LONGDBL 0x0002 /* L: long long or long double */
|
||||||
#define SHORT 0x004 /* h: short */
|
#define SHORT 0x0004 /* h: short */
|
||||||
#define SUPPRESS 0x008 /* *: suppress assignment */
|
#define SUPPRESS 0x0008 /* *: suppress assignment */
|
||||||
#define POINTER 0x010 /* weird %p pointer (`fake hex') */
|
#define POINTER 0x0010 /* weird %p pointer (`fake hex') */
|
||||||
#define NOSKIP 0x020 /* do not skip blanks */
|
#define NOSKIP 0x0020 /* do not skip blanks */
|
||||||
#define NUMBER_SIGNED 0x040 /* signed integer */
|
#define NUMBER_SIGNED 0x0040 /* signed integer */
|
||||||
#define GROUP 0x080 /* ': group numbers */
|
#define GROUP 0x0080 /* ': group numbers */
|
||||||
#define MALLOC 0x100 /* a: malloc strings */
|
#define MALLOC 0x0100 /* a: malloc strings */
|
||||||
#define CHAR 0x200 /* hh: char */
|
#define CHAR 0x0200 /* hh: char */
|
||||||
#define I18N 0x400 /* I: use locale's digits */
|
#define I18N 0x0400 /* I: use locale's digits */
|
||||||
#define HEXA_FLOAT 0x800 /* hexadecimal float */
|
#define HEXA_FLOAT 0x0800 /* hexadecimal float */
|
||||||
|
#define READ_POINTER 0x1000 /* this is a pointer value */
|
||||||
|
|
||||||
|
|
||||||
#include <locale/localeinfo.h>
|
#include <locale/localeinfo.h>
|
||||||
@@ -236,8 +237,6 @@ _IO_vfscanf_internal (_IO_FILE *s, const char *format, _IO_va_list argptr,
|
|||||||
possibly be matched even if in the input stream no character is
|
possibly be matched even if in the input stream no character is
|
||||||
available anymore. */
|
available anymore. */
|
||||||
int skip_space = 0;
|
int skip_space = 0;
|
||||||
/* Nonzero if we are reading a pointer. */
|
|
||||||
int read_pointer;
|
|
||||||
/* Workspace. */
|
/* Workspace. */
|
||||||
CHAR_T *tw; /* Temporary pointer. */
|
CHAR_T *tw; /* Temporary pointer. */
|
||||||
CHAR_T *wp = NULL; /* Workspace. */
|
CHAR_T *wp = NULL; /* Workspace. */
|
||||||
@@ -400,9 +399,6 @@ _IO_vfscanf_internal (_IO_FILE *s, const char *format, _IO_va_list argptr,
|
|||||||
/* This is the start of the conversion string. */
|
/* This is the start of the conversion string. */
|
||||||
flags = 0;
|
flags = 0;
|
||||||
|
|
||||||
/* Not yet decided whether we read a pointer or not. */
|
|
||||||
read_pointer = 0;
|
|
||||||
|
|
||||||
/* Initialize state of modifiers. */
|
/* Initialize state of modifiers. */
|
||||||
argpos = 0;
|
argpos = 0;
|
||||||
|
|
||||||
@@ -1489,7 +1485,7 @@ _IO_vfscanf_internal (_IO_FILE *s, const char *format, _IO_va_list argptr,
|
|||||||
/* There was no number. If we are supposed to read a pointer
|
/* There was no number. If we are supposed to read a pointer
|
||||||
we must recognize "(nil)" as well. */
|
we must recognize "(nil)" as well. */
|
||||||
if (__builtin_expect (wpsize == 0
|
if (__builtin_expect (wpsize == 0
|
||||||
&& read_pointer
|
&& (flags & READ_POINTER)
|
||||||
&& (width < 0 || width >= 0)
|
&& (width < 0 || width >= 0)
|
||||||
&& c == '('
|
&& c == '('
|
||||||
&& TOLOWER (inchar ()) == L_('n')
|
&& TOLOWER (inchar ()) == L_('n')
|
||||||
@@ -1981,7 +1977,7 @@ _IO_vfscanf_internal (_IO_FILE *s, const char *format, _IO_va_list argptr,
|
|||||||
got_dot = 1;
|
got_dot = 1;
|
||||||
}
|
}
|
||||||
else if (n == 10 && (flags & GROUP) != 0
|
else if (n == 10 && (flags & GROUP) != 0
|
||||||
&& thousands != NULL && ! got_dot)
|
&& ! got_dot)
|
||||||
{
|
{
|
||||||
/* Add all the characters. */
|
/* Add all the characters. */
|
||||||
for (cmpp = thousands; *cmpp != '\0';
|
for (cmpp = thousands; *cmpp != '\0';
|
||||||
@@ -2574,7 +2570,7 @@ _IO_vfscanf_internal (_IO_FILE *s, const char *format, _IO_va_list argptr,
|
|||||||
flags &= ~(SHORT|LONGDBL);
|
flags &= ~(SHORT|LONGDBL);
|
||||||
if (need_long)
|
if (need_long)
|
||||||
flags |= LONG;
|
flags |= LONG;
|
||||||
read_pointer = 1;
|
flags |= READ_POINTER;
|
||||||
goto number;
|
goto number;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
|
Reference in New Issue
Block a user