summaryrefslogtreecommitdiff
path: root/resource.c
diff options
context:
space:
mode:
authorDenys Vlasenko <vda.linux@googlemail.com>2012-02-27 14:37:48 +0100
committerDenys Vlasenko <vda.linux@googlemail.com>2012-02-27 14:37:48 +0100
commit1945ccc3fbd5b56008c4a6b0cdd4611616201675 (patch)
treecd3ccfbe31c8e9a2a795baf172c783a33270e381 /resource.c
parent72879c6a35cd5afa7f58ee7bc32e4dcd8e65bd9a (diff)
downloadstrace-1945ccc3fbd5b56008c4a6b0cdd4611616201675.tar.gz
strace-1945ccc3fbd5b56008c4a6b0cdd4611616201675.tar.bz2
strace-1945ccc3fbd5b56008c4a6b0cdd4611616201675.tar.xz
Assorted trivial optimizations
text data bss dec hex filename 236448 672 19044 256164 3e8a4 strace.before 236360 672 19044 256076 3e84c strace * file.c (sprintmode): Use smaller static buffer, eliminate strlen call. (sprinttime): Use smaller static buffer. (printstat_sparc64): Coalesce two printing calls into one. (printstat_powerpc32): Likewise. (printcompat_statfs6): Likewise. (sys_utime): Do not fetch personality_wordsize[current_personality] repeatedly - cache it in local variable instead. * process.c (printargv): Likewise. * resource.c (sprintrlim): Return const char*, not char*. This allows to eliminate sprintf(buf, "RLIM_INFINITY"). Use smaller static buffer. (sprintrlim64): Likewise. * strace.c (strerror): Use smaller static buffer. (strsignal): Likewise. Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
Diffstat (limited to 'resource.c')
-rw-r--r--resource.c18
1 files changed, 10 insertions, 8 deletions
diff --git a/resource.c b/resource.c
index 09744d7..f5cec21 100644
--- a/resource.c
+++ b/resource.c
@@ -104,14 +104,15 @@ static const struct xlat resources[] = {
};
#if !HAVE_LONG_LONG_RLIM_T
-static char *
+static const char *
sprintrlim(long lim)
{
- static char buf[32];
+ static char buf[sizeof(long)*3 + sizeof("%ld*1024")];
if (lim == RLIM_INFINITY)
- sprintf(buf, "RLIM_INFINITY");
- else if (lim > 1024 && lim%1024 == 0)
+ return "RLIM_INFINITY";
+
+ if (lim > 1024 && lim%1024 == 0)
sprintf(buf, "%ld*1024", lim/1024);
else
sprintf(buf, "%ld", lim);
@@ -192,14 +193,15 @@ sys_setrlimit(struct tcb *tcp)
#endif /* !HAVE_LONG_LONG_RLIM_T */
#if _LFS64_LARGEFILE || HAVE_LONG_LONG_RLIM_T
-static char *
+static const char *
sprintrlim64(rlim64_t lim)
{
- static char buf[64];
+ static char buf[sizeof(long long)*3 + sizeof("%lld*1024")];
if (lim == RLIM64_INFINITY)
- sprintf(buf, "RLIM64_INFINITY");
- else if (lim > 1024 && lim%1024 == 0)
+ return "RLIM64_INFINITY";
+
+ if (lim > 1024 && lim%1024 == 0)
sprintf(buf, "%lld*1024", (long long) lim/1024);
else
sprintf(buf, "%lld", (long long) lim);