]> git.proxmox.com Git - mirror_lxcfs.git/commitdiff
Remove unused chunks in caching code
authorSeth Forshee <seth.forshee@canonical.com>
Thu, 28 Jan 2016 16:17:42 +0000 (17:17 +0100)
committerSeth Forshee <seth.forshee@canonical.com>
Thu, 28 Jan 2016 16:56:31 +0000 (17:56 +0100)
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 <seth.forshee@canonical.com>
lxcfs.c

diff --git a/lxcfs.c b/lxcfs.c
index a57c07fba812abb791eadd7b5212980bce6c9850..a1470bf2a3e1154daa3cc84c23067e6b517a4e09 100644 (file)
--- 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)