summaryrefslogtreecommitdiff
path: root/file.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 /file.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 'file.c')
-rw-r--r--file.c30
1 files changed, 13 insertions, 17 deletions
diff --git a/file.c b/file.c
index 69b3c84..be1b1a7 100644
--- a/file.c
+++ b/file.c
@@ -666,7 +666,9 @@ static const struct xlat modetypes[] = {
static const char *
sprintmode(int mode)
{
- static char buf[64];
+ static char buf[sizeof("S_IFSOCK|S_ISUID|S_ISGID|S_ISVTX|%o")
+ + sizeof(int)*3
+ + /*paranoia:*/ 8];
const char *s;
if ((mode & S_IFMT) == 0)
@@ -675,13 +677,13 @@ sprintmode(int mode)
sprintf(buf, "%#o", mode);
return buf;
}
- sprintf(buf, "%s%s%s%s", s,
+ s = buf + sprintf(buf, "%s%s%s%s", s,
(mode & S_ISUID) ? "|S_ISUID" : "",
(mode & S_ISGID) ? "|S_ISGID" : "",
(mode & S_ISVTX) ? "|S_ISVTX" : "");
mode &= ~(S_IFMT|S_ISUID|S_ISGID|S_ISVTX);
if (mode)
- sprintf(buf + strlen(buf), "|%#o", mode);
+ sprintf((char*)s, "|%#o", mode);
s = (*buf == '|') ? buf + 1 : buf;
return *s ? s : "0";
}
@@ -690,7 +692,7 @@ static char *
sprinttime(time_t t)
{
struct tm *tmp;
- static char buf[32];
+ static char buf[sizeof("yyyy/mm/dd-hh:mm:ss")];
if (t == 0) {
strcpy(buf, "0");
@@ -818,8 +820,7 @@ printstat_sparc64(struct tcb *tcp, long addr)
if (!abbrev(tcp)) {
tprintf("st_atime=%s, ", sprinttime(statbuf.st_atime));
tprintf("st_mtime=%s, ", sprinttime(statbuf.st_mtime));
- tprintf("st_ctime=%s", sprinttime(statbuf.st_ctime));
- tprints("}");
+ tprintf("st_ctime=%s}", sprinttime(statbuf.st_ctime));
}
else
tprints("...}");
@@ -884,8 +885,7 @@ printstat_powerpc32(struct tcb *tcp, long addr)
if (!abbrev(tcp)) {
tprintf("st_atime=%s, ", sprinttime(statbuf.st_atime));
tprintf("st_mtime=%s, ", sprinttime(statbuf.st_mtime));
- tprintf("st_ctime=%s", sprinttime(statbuf.st_ctime));
- tprints("}");
+ tprintf("st_ctime=%s}", sprinttime(statbuf.st_ctime));
}
else
tprints("...}");
@@ -1742,8 +1742,7 @@ printcompat_statfs64(struct tcb *tcp, long addr)
statbuf.f_fsid.__val[0], statbuf.f_fsid.__val[1]);
tprintf(", f_namelen=%lu", (unsigned long)statbuf.f_namelen);
tprintf(", f_frsize=%lu", (unsigned long)statbuf.f_frsize);
- tprintf(", f_flags=%lu", (unsigned long)statbuf.f_frsize);
- tprints("}");
+ tprintf(", f_flags=%lu}", (unsigned long)statbuf.f_frsize);
}
int
@@ -2088,6 +2087,7 @@ sys_utime(struct tcb *tcp)
long utl[2];
int uti[2];
} u;
+ unsigned wordsize = personality_wordsize[current_personality];
if (entering(tcp)) {
printpath(tcp, tcp->u_arg[0]);
@@ -2096,17 +2096,13 @@ sys_utime(struct tcb *tcp)
tprints("NULL");
else if (!verbose(tcp))
tprintf("%#lx", tcp->u_arg[1]);
- else if (umoven(tcp, tcp->u_arg[1],
- 2 * personality_wordsize[current_personality],
- (char *) &u) < 0)
+ else if (umoven(tcp, tcp->u_arg[1], 2 * wordsize, (char *) &u) < 0)
tprints("[?, ?]");
- else if (personality_wordsize[current_personality]
- == sizeof u.utl[0]) {
+ else if (wordsize == sizeof u.utl[0]) {
tprintf("[%s,", sprinttime(u.utl[0]));
tprintf(" %s]", sprinttime(u.utl[1]));
}
- else if (personality_wordsize[current_personality]
- == sizeof u.uti[0]) {
+ else if (wordsize == sizeof u.uti[0]) {
tprintf("[%s,", sprinttime(u.uti[0]));
tprintf(" %s]", sprinttime(u.uti[1]));
}