From b92bea5d2a9481de69bb627a7b442a9f58fca43d Mon Sep 17 00:00:00 2001 From: Zbigniew Jędrzejewski-Szmek Date: Sun, 24 Mar 2013 19:59:00 -0400 Subject: Use initalization instead of explicit zeroing MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Before, we would initialize many fields twice: first by filling the structure with zeros, and then a second time with the real values. We can let the compiler do the job for us, avoiding one copy. A downside of this patch is that text gets slightly bigger. This is because all zero() calls are effectively inlined: $ size build/.libs/systemd text data bss dec hex filename before 897737 107300 2560 1007597 f5fed build/.libs/systemd after 897873 107300 2560 1007733 f6075 build/.libs/systemd … actually less than 1‰. A few asserts that the parameter is not null had to be removed. I don't think this changes much, because first, it is quite unlikely for the assert to fail, and second, an immediate SEGV is almost as good as an assert. --- src/shared/utmp-wtmp.c | 18 ++++++------------ 1 file changed, 6 insertions(+), 12 deletions(-) (limited to 'src/shared/utmp-wtmp.c') diff --git a/src/shared/utmp-wtmp.c b/src/shared/utmp-wtmp.c index 3494b56908..5ee3d22e71 100644 --- a/src/shared/utmp-wtmp.c +++ b/src/shared/utmp-wtmp.c @@ -33,7 +33,7 @@ #include "utmp-wtmp.h" int utmp_get_runlevel(int *runlevel, int *previous) { - struct utmpx lookup, *found; + struct utmpx *found, lookup = { .ut_type = RUN_LVL }; int r; const char *e; @@ -66,9 +66,6 @@ int utmp_get_runlevel(int *runlevel, int *previous) { setutxent(); - zero(lookup); - lookup.ut_type = RUN_LVL; - if (!(found = getutxid(&lookup))) r = -errno; else { @@ -102,14 +99,12 @@ static void init_timestamp(struct utmpx *store, usec_t t) { } static void init_entry(struct utmpx *store, usec_t t) { - struct utsname uts; + struct utsname uts = {}; assert(store); init_timestamp(store, t); - zero(uts); - if (uname(&uts) >= 0) strncpy(store->ut_host, uts.release, sizeof(store->ut_host)); @@ -311,7 +306,10 @@ static int write_to_terminal(const char *tty, const char *message) { while (left > 0) { ssize_t n; - struct pollfd pollfd; + struct pollfd pollfd = { + .fd = fd, + .events = POLLOUT, + }; usec_t t; int k; @@ -320,10 +318,6 @@ static int write_to_terminal(const char *tty, const char *message) { if (t >= end) return -ETIME; - zero(pollfd); - pollfd.fd = fd; - pollfd.events = POLLOUT; - k = poll(&pollfd, 1, (end - t) / USEC_PER_MSEC); if (k < 0) return -errno; -- cgit v1.2.3-54-g00ecf