From 2670293c68fe700a5320e3d37815091e3590d39a Mon Sep 17 00:00:00 2001
From: Adam Spragg <adam@spra.gg>
Date: Thu, 7 Jul 2022 13:57:37 +0100
Subject: Return early if there are no xattrs

Saves one malloc(3) and one listxattr(2) per file that has no xattrs.

On my system, this improves `time metastore -d /usr >/dev/null` from:

    real    0m2.347s
    user    0m0.732s
    sys     0m1.603s

to:

    real    0m2.183s
    user    0m0.733s
    sys     0m1.435s

Average of 5 runs, on a warm cache, reducing runtime by roughly 7%.
---
 src/metaentry.c | 2 ++
 1 file changed, 2 insertions(+)

(limited to 'src')

diff --git a/src/metaentry.c b/src/metaentry.c
index fe1c6d1..146fcf9 100644
--- a/src/metaentry.c
+++ b/src/metaentry.c
@@ -251,6 +251,8 @@ mentry_create(const char *path)
 		    path, strerror(errno));
 		return NULL;
 	}
+	if (lsize == 0)
+		return mentry;
 
 	list = xmalloc(lsize);
 	lsize = listxattr(path, list, lsize);
-- 
cgit v1.2.1