[4/6] vfprintf: Move jump table definition and the macros out of function
diff mbox

Message ID f8ad26637a01b8173077d6dd38dd13cc31bbf22d.1425246936.git.fweimer@redhat.com
State New
Headers show

Commit Message

Florian Weimer March 1, 2015, 9 p.m. UTC
The second jump table will be moved to a separate function
in the next commit.
---
 stdio-common/vfprintf.c | 108 ++++++++++++++++++++++++------------------------
 1 file changed, 54 insertions(+), 54 deletions(-)

Comments

Carlos O'Donell March 5, 2015, 7:38 p.m. UTC | #1
On 03/01/2015 04:00 PM, Florian Weimer wrote:
> The second jump table will be moved to a separate function
> in the next commit.
> ---
>  stdio-common/vfprintf.c | 108 ++++++++++++++++++++++++------------------------
>  1 file changed, 54 insertions(+), 54 deletions(-)

How does this impact the generated code and performance of these routines?

Cheers,
Carlos.
Florian Weimer March 6, 2015, 10:35 a.m. UTC | #2
On 03/05/2015 08:38 PM, Carlos O'Donell wrote:
> On 03/01/2015 04:00 PM, Florian Weimer wrote:
>> The second jump table will be moved to a separate function
>> in the next commit.
>> ---
>>  stdio-common/vfprintf.c | 108 ++++++++++++++++++++++++------------------------
>>  1 file changed, 54 insertions(+), 54 deletions(-)
> 
> How does this impact the generated code and performance of these routines?

The generated code is identical.

Or is your question about next change (the printf_positional function)?
Carlos O'Donell March 6, 2015, 3:41 p.m. UTC | #3
On 03/06/2015 05:35 AM, Florian Weimer wrote:
> On 03/05/2015 08:38 PM, Carlos O'Donell wrote:
>> On 03/01/2015 04:00 PM, Florian Weimer wrote:
>>> The second jump table will be moved to a separate function
>>> in the next commit.
>>> ---
>>>  stdio-common/vfprintf.c | 108 ++++++++++++++++++++++++------------------------
>>>  1 file changed, 54 insertions(+), 54 deletions(-)
>>
>> How does this impact the generated code and performance of these routines?
> 
> The generated code is identical.
> 
> Or is your question about next change (the printf_positional function)?

The question was for this specific change, but it does apply equally
across the board. I see your other post about the fact that it actually
improves performance and I'll reply there.

c.

Patch
diff mbox

diff --git a/stdio-common/vfprintf.c b/stdio-common/vfprintf.c
index dcc24b3..da52dbc 100644
--- a/stdio-common/vfprintf.c
+++ b/stdio-common/vfprintf.c
@@ -212,60 +212,10 @@  static int printf_unknown (FILE *, const struct printf_info *,
 static CHAR_T *group_number (CHAR_T *, CHAR_T *, const char *, THOUSANDS_SEP_T)
      __THROW internal_function;
 
-/* The function itself.  */
-int
-vfprintf (FILE *s, const CHAR_T *format, va_list ap)
-{
-  /* The character used as thousands separator.  */
-  THOUSANDS_SEP_T thousands_sep = 0;
-
-  /* The string describing the size of groups of digits.  */
-  const char *grouping;
-
-  /* Place to accumulate the result.  */
-  int done;
-
-  /* Current character in format string.  */
-  const UCHAR_T *f;
-
-  /* End of leading constant string.  */
-  const UCHAR_T *lead_str_end;
-
-  /* Points to next format specifier.  */
-  const UCHAR_T *end_of_spec;
-
-  /* Buffer intermediate results.  */
-#define WORK_BUFFER_SIZE 1000
-  CHAR_T work_buffer[WORK_BUFFER_SIZE];
-  CHAR_T *workstart = NULL;
-  CHAR_T *workend;
-
-  /* We have to save the original argument pointer.  */
-  va_list ap_save;
-
-  /* Count number of specifiers we already processed.  */
-  int nspecs_done;
-
-  /* For the %m format we may need the current `errno' value.  */
-  int save_errno = errno;
-
-  /* 1 if format is in read-only memory, -1 if it is in writable memory,
-     0 if unknown.  */
-  int readonly_format = 0;
-
-  /* For the argument descriptions, which may be allocated on the heap.  */
-  void *args_malloced = NULL;
-
-  /* For positional argument handling.  */
-  struct printf_spec *specs;
-
-  /* Track if we malloced the SPECS array and thus must free it.  */
-  bool specs_malloced = false;
-
-  /* This table maps a character into a number representing a
-     class.  In each step there is a destination label for each
-     class.  */
-  static const uint8_t jump_table[] =
+/* Jump tables.  This table maps a character into a number
+   representing a class.  In each step there is a destination label
+   for each class.  */
+static const uint8_t jump_table[] =
   {
     /* ' ' */  1,            0,            0, /* '#' */  4,
 	       0, /* '%' */ 14,            0, /* '\''*/  6,
@@ -1266,6 +1216,56 @@  vfprintf (FILE *s, const CHAR_T *format, va_list ap)
       break;
 #endif
 
+/* The function itself.  */
+int
+vfprintf (FILE *s, const CHAR_T *format, va_list ap)
+{
+  /* The character used as thousands separator.  */
+  THOUSANDS_SEP_T thousands_sep = 0;
+
+  /* The string describing the size of groups of digits.  */
+  const char *grouping;
+
+  /* Place to accumulate the result.  */
+  int done;
+
+  /* Current character in format string.  */
+  const UCHAR_T *f;
+
+  /* End of leading constant string.  */
+  const UCHAR_T *lead_str_end;
+
+  /* Points to next format specifier.  */
+  const UCHAR_T *end_of_spec;
+
+  /* Buffer intermediate results.  */
+#define WORK_BUFFER_SIZE 1000
+  CHAR_T work_buffer[WORK_BUFFER_SIZE];
+  CHAR_T *workstart = NULL;
+  CHAR_T *workend;
+
+  /* We have to save the original argument pointer.  */
+  va_list ap_save;
+
+  /* Count number of specifiers we already processed.  */
+  int nspecs_done;
+
+  /* For the %m format we may need the current `errno' value.  */
+  int save_errno = errno;
+
+  /* 1 if format is in read-only memory, -1 if it is in writable memory,
+     0 if unknown.  */
+  int readonly_format = 0;
+
+  /* For the argument descriptions, which may be allocated on the heap.  */
+  void *args_malloced = NULL;
+
+  /* For positional argument handling.  */
+  struct printf_spec *specs;
+
+  /* Track if we malloced the SPECS array and thus must free it.  */
+  bool specs_malloced = false;
+
   /* Orient the stream.  */
 #ifdef ORIENT
   ORIENT;