commit:     5d20d5da741d6e6665b7c1e4fb6873d22f186222
Author:     Mike Frysinger <vapier <AT> gentoo <DOT> org>
AuthorDate: Sat Jun  6 05:54:34 2015 +0000
Commit:     Mike Frysinger <vapier <AT> gentoo <DOT> org>
CommitDate: Sat Jun  6 05:54:34 2015 +0000
URL:        https://gitweb.gentoo.org/proj/portage-utils.git/commit/?id=5d20d5da

cache: optimize the common case slightly

Do the cache sanity check immediately on the assumption that it will be
sane the majority of the time.  No point in opening the portdir and such
just to close it immediately.

 main.c | 24 +++++++++++++-----------
 1 file changed, 13 insertions(+), 11 deletions(-)

diff --git a/main.c b/main.c
index df1e309..66b3b30 100644
--- a/main.c
+++ b/main.c
@@ -915,6 +915,19 @@ initialize_flat(int cache_type, bool force)
        int frac, secs, count;
        FILE *fp;
 
+       xasprintf(&cache_file, "%s/dep/%s/%s", portedb, portdir,
+               (cache_type == CACHE_EBUILD ? ".ebuild.x" : ".metadata.x"));
+
+       /* If we aren't forcing a regen, make sure the file is somewhat sane. */
+       if (!force) {
+               if (stat(cache_file, &st) != -1)
+                       if (st.st_size)
+                               return cache_file;
+       }
+
+       if (!quiet)
+               warn("Updating ebuild %scache ... ", cache_type == CACHE_EBUILD 
? "" : "meta");
+
        count = frac = secs = 0;
 
        int portdir_fd, subdir_fd;
@@ -933,17 +946,6 @@ initialize_flat(int cache_type, bool force)
                        portcachedir_type = CACHE_METADATA_MD5;
        } else
                subdir_fd = portdir_fd;
-       xasprintf(&cache_file, "%s/dep/%s/%s", portedb, portdir,
-               (cache_type == CACHE_EBUILD ? ".ebuild.x" : ".metadata.x"));
-
-       /* If we aren't forcing a regen, make sure the file is somewhat sane. */
-       if (!force) {
-               if (stat(cache_file, &st) != -1)
-                       if (st.st_size)
-                               goto ret;
-       }
-       if (!quiet)
-               warn("Updating ebuild %scache ... ", cache_type == CACHE_EBUILD 
? "" : "meta");
 
        if ((fp = fopen(cache_file, "we")) == NULL) {
                warnfp("opening cache failed: %s", cache_file);

Reply via email to