From 711b4030d2845dcf4ef697680e1574daf980c07f Mon Sep 17 00:00:00 2001 From: Seth Forshee Date: Thu, 28 Jan 2016 17:17:42 +0100 Subject: [PATCH] Remove unused chunks in caching code Several pieces of code which deal with caching contents for proc files contain code like this: if (l >= cache_size) { ... goto err; } if (l < cache_size) { ... } else { ... } When the first condition is false the second condition will always be true, so the code in the else block is never used. The second if/else statement can then just be replaced with the code from the if block. Signed-off-by: Seth Forshee --- lxcfs.c | 55 +++++++++++++------------------------------------------ 1 file changed, 13 insertions(+), 42 deletions(-) diff --git a/lxcfs.c b/lxcfs.c index a57c07f..a1470bf 100644 --- a/lxcfs.c +++ b/lxcfs.c @@ -2191,16 +2191,9 @@ static int read_file(const char *path, char *buf, size_t size, rv = 0; goto err; } - if (l < cache_size) { - cache += l; - cache_size -= l; - total_len += l; - } else { - cache += cache_size; - total_len += cache_size; - cache_size = 0; - break; - } + cache += l; + cache_size -= l; + total_len += l; } d->size = total_len; @@ -2491,16 +2484,9 @@ static int proc_cpuinfo_read(char *buf, size_t size, off_t offset, rv = 0; goto err; } - if (l < cache_size){ - cache += l; - cache_size -= l; - total_len += l; - }else{ - cache += cache_size; - total_len += cache_size; - cache_size = 0; - break; - } + cache += l; + cache_size -= l; + total_len += l; } continue; } @@ -2516,16 +2502,9 @@ static int proc_cpuinfo_read(char *buf, size_t size, off_t offset, rv = 0; goto err; } - if (l < cache_size) { - cache += l; - cache_size -= l; - total_len += l; - } else { - cache += cache_size; - total_len += cache_size; - cache_size = 0; - break; - } + cache += l; + cache_size -= l; + total_len += l; } } @@ -2616,18 +2595,10 @@ static int proc_stat_read(char *buf, size_t size, off_t offset, rv = 0; goto err; } - if (l < cache_size) { - cache += l; - cache_size -= l; - total_len += l; - continue; - } else { - //no more space, break it - cache += cache_size; - total_len += cache_size; - cache_size = 0; - break; - } + cache += l; + cache_size -= l; + total_len += l; + continue; } if (sscanf(cpu_char, "%d", &cpu) != 1) -- 2.39.2