[libvirt PATCH 03/19] commandhelper: Simplify envsort

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Comparing only the keys produces the same result as comparing keys and
value. The latter saves two invocations of each `strndup` and `free`.

Signed-off-by: Tim Wiederhake <twiederh@xxxxxxxxxx>
---
 tests/commandhelper.c | 17 +----------------
 1 file changed, 1 insertion(+), 16 deletions(-)

diff --git a/tests/commandhelper.c b/tests/commandhelper.c
index 2b937979c0..05e3879688 100644
--- a/tests/commandhelper.c
+++ b/tests/commandhelper.c
@@ -39,22 +39,7 @@ static int envsort(const void *a, const void *b)
 {
     const char *const*astrptr = a;
     const char *const*bstrptr = b;
-    const char *astr = *astrptr;
-    const char *bstr = *bstrptr;
-    char *aeq = strchr(astr, '=');
-    char *beq = strchr(bstr, '=');
-    char *akey;
-    char *bkey;
-    int ret;
-
-    if (!(akey = strndup(astr, aeq - astr)))
-        abort();
-    if (!(bkey = strndup(bstr, beq - bstr)))
-        abort();
-    ret = strcmp(akey, bkey);
-    free(akey);
-    free(bkey);
-    return ret;
+    return strcmp(*astrptr, *bstrptr);
 }
 
 int main(int argc, char **argv) {
-- 
2.26.2




[Index of Archives]     [Virt Tools]     [Libvirt Users]     [Lib OS Info]     [Fedora Users]     [Fedora Desktop]     [Fedora SELinux]     [Big List of Linux Books]     [Yosemite News]     [KDE Users]     [Fedora Tools]

  Powered by Linux