diff options
author | Paul Eggert <eggert@cs.ucla.edu> | 2012-06-25 19:33:51 -0700 |
---|---|---|
committer | Paul Eggert <eggert@cs.ucla.edu> | 2012-06-25 19:33:51 -0700 |
commit | 99027bdd81f63ea690394a153ef49a08f55e498d (patch) | |
tree | b7b7083784549ae09d9e688441168627262d4b6d /src/doprnt.c | |
parent | cf38a720e81b545f90dc7be81891d94df6ed059a (diff) | |
download | emacs-99027bdd81f63ea690394a153ef49a08f55e498d.tar.gz |
Use sprintf return value instead of invoking strlen on result.
In the old days this wasn't portable, since some sprintf
implementations returned char *. But they died out years ago and
Emacs already assumes sprintf returns int.
Similarly for float_to_string.
This patch speeds up (number-to-string 1000) by 3% on Fedora 15 x86-64.
* ccl.c (ccl_driver):
* character.c (string_escape_byte8):
* data.c (Fnumber_to_string):
* doprnt.c (doprnt):
* print.c (print_object):
* xdisp.c (message_dolog):
* xfns.c (syms_of_xfns):
Use sprintf or float_to_string result to avoid need to call strlen.
* data.c (Fnumber_to_string):
Use make_unibyte_string, since the string must be ASCII.
* lisp.h, print.c (float_to_string): Now returns int length.
* term.c (produce_glyphless_glyph):
Use sprintf result rather than recomputing it.
Diffstat (limited to 'src/doprnt.c')
-rw-r--r-- | src/doprnt.c | 24 |
1 files changed, 11 insertions, 13 deletions
diff --git a/src/doprnt.c b/src/doprnt.c index b106ffb1938..07bbcff7081 100644 --- a/src/doprnt.c +++ b/src/doprnt.c @@ -275,32 +275,32 @@ doprnt (char *buffer, ptrdiff_t bufsize, const char *format, case no_modifier: { int v = va_arg (ap, int); - sprintf (sprintf_buffer, fmtcpy, v); + tem = sprintf (sprintf_buffer, fmtcpy, v); } break; case long_modifier: { long v = va_arg (ap, long); - sprintf (sprintf_buffer, fmtcpy, v); + tem = sprintf (sprintf_buffer, fmtcpy, v); } break; case pD_modifier: signed_pD_modifier: { ptrdiff_t v = va_arg (ap, ptrdiff_t); - sprintf (sprintf_buffer, fmtcpy, v); + tem = sprintf (sprintf_buffer, fmtcpy, v); } break; case pI_modifier: { EMACS_INT v = va_arg (ap, EMACS_INT); - sprintf (sprintf_buffer, fmtcpy, v); + tem = sprintf (sprintf_buffer, fmtcpy, v); } break; case pM_modifier: { intmax_t v = va_arg (ap, intmax_t); - sprintf (sprintf_buffer, fmtcpy, v); + tem = sprintf (sprintf_buffer, fmtcpy, v); } break; } @@ -315,13 +315,13 @@ doprnt (char *buffer, ptrdiff_t bufsize, const char *format, case no_modifier: { unsigned v = va_arg (ap, unsigned); - sprintf (sprintf_buffer, fmtcpy, v); + tem = sprintf (sprintf_buffer, fmtcpy, v); } break; case long_modifier: { unsigned long v = va_arg (ap, unsigned long); - sprintf (sprintf_buffer, fmtcpy, v); + tem = sprintf (sprintf_buffer, fmtcpy, v); } break; case pD_modifier: @@ -329,13 +329,13 @@ doprnt (char *buffer, ptrdiff_t bufsize, const char *format, case pI_modifier: { EMACS_UINT v = va_arg (ap, EMACS_UINT); - sprintf (sprintf_buffer, fmtcpy, v); + tem = sprintf (sprintf_buffer, fmtcpy, v); } break; case pM_modifier: { uintmax_t v = va_arg (ap, uintmax_t); - sprintf (sprintf_buffer, fmtcpy, v); + tem = sprintf (sprintf_buffer, fmtcpy, v); } break; } @@ -348,7 +348,7 @@ doprnt (char *buffer, ptrdiff_t bufsize, const char *format, case 'g': { double d = va_arg (ap, double); - sprintf (sprintf_buffer, fmtcpy, d); + tem = sprintf (sprintf_buffer, fmtcpy, d); /* Now copy into final output, truncating as necessary. */ string = sprintf_buffer; goto doit; @@ -369,7 +369,6 @@ doprnt (char *buffer, ptrdiff_t bufsize, const char *format, /* Copy string into final output, truncating if no room. */ doit: /* Coming here means STRING contains ASCII only. */ - tem = strlen (string); if (STRING_BYTES_BOUND < tem) error ("Format width or precision too large"); width = tem; @@ -413,8 +412,7 @@ doprnt (char *buffer, ptrdiff_t bufsize, const char *format, bufsize = 0; continue; } - else - memcpy (bufptr, string, tem); + memcpy (bufptr, string, tem); bufptr += tem; bufsize -= tem; if (minlen < 0) |