Return-Path: X-Original-To: notmuch@notmuchmail.org Delivered-To: notmuch@notmuchmail.org Received: from localhost (localhost [127.0.0.1]) by olra.theworths.org (Postfix) with ESMTP id 2D1C1431FDA for ; Sun, 19 Jan 2014 12:32:55 -0800 (PST) X-Virus-Scanned: Debian amavisd-new at olra.theworths.org X-Amavis-Alert: BAD HEADER SECTION, Duplicate header field: "References" X-Spam-Flag: NO X-Spam-Score: -0.7 X-Spam-Level: X-Spam-Status: No, score=-0.7 tagged_above=-999 required=5 tests=[RCVD_IN_DNSWL_LOW=-0.7] autolearn=disabled Received: from olra.theworths.org ([127.0.0.1]) by localhost (olra.theworths.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id Ps5hzXYP0CpR for ; Sun, 19 Jan 2014 12:32:49 -0800 (PST) Received: from mail-ee0-f41.google.com (mail-ee0-f41.google.com [74.125.83.41]) (using TLSv1 with cipher RC4-SHA (128/128 bits)) (No client certificate requested) by olra.theworths.org (Postfix) with ESMTPS id A3E5C431FC3 for ; Sun, 19 Jan 2014 12:32:45 -0800 (PST) Received: by mail-ee0-f41.google.com with SMTP id e49so3129468eek.28 for ; Sun, 19 Jan 2014 12:32:44 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:in-reply-to:references; bh=cGu1awp5zoGgbQDv131j+/NvXXFicBGwWJMMOMjBvus=; b=BUHdDfQtTziEIEi9mDX0AwU1W6st98KO7FnJOQy6pRxOR3q/ovs6aPYWPK/SLzGSVW KqxSqIA0abtET/Wrx0LoTIVT5mvVj5Gn8cC12BYjfnrFLm8YMQHTGwEjVNcXeBwf9Ord 3S7AfCzEiaGQuLpq5CpbG7o+C93oWK9TDfN4J4K9ges4C9AVyTjMJGUyRzukVQ9LG8H/ hliSv/oW/IQl6teNip4YbP8J7Y46sx4/gcpa772BTv7SBN51fzy1/O1hyt50toU0xLrh mR0njbUPyGBjZNFYOldrzu7uM+T3syHSgy0+TrDgLHWkM6vMdvMNIl1TB4wNH0bLmxhb XdNA== X-Gm-Message-State: ALoCoQk5bCdQQJtgzq4V+e4HEyn2yGOkaH7gnLEWXihVeKpkel6WOfZYCboX19ntu1zNd8lMTBG+ X-Received: by 10.14.99.66 with SMTP id w42mr1129032eef.63.1390163564378; Sun, 19 Jan 2014 12:32:44 -0800 (PST) Received: from localhost (dsl-hkibrasgw2-58c36f-91.dhcp.inet.fi. [88.195.111.91]) by mx.google.com with ESMTPSA id n7sm46512417eef.5.2014.01.19.12.32.43 for (version=TLSv1.2 cipher=RC4-SHA bits=128/128); Sun, 19 Jan 2014 12:32:43 -0800 (PST) From: Jani Nikula To: notmuch@notmuchmail.org Subject: [PATCH 3/7] cli: use dirent_type in count_files too Date: Sun, 19 Jan 2014 22:32:24 +0200 Message-Id: <024420e6f583f7e4c76ded29b5c9158608dd8f6c.1390163335.git.jani@nikula.org> X-Mailer: git-send-email 1.8.5.2 In-Reply-To: References: In-Reply-To: References: X-BeenThere: notmuch@notmuchmail.org X-Mailman-Version: 2.1.13 Precedence: list List-Id: "Use and development of the notmuch mail system." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sun, 19 Jan 2014 20:32:55 -0000 Avoid an extra stat per file, if possible, also when counting the files for initial indexing. --- notmuch-new.c | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/notmuch-new.c b/notmuch-new.c index 7f3b3b0..e6ca841 100644 --- a/notmuch-new.c +++ b/notmuch-new.c @@ -702,9 +702,9 @@ count_files (const char *path, int *count, add_files_state_t *state) { struct dirent *entry = NULL; char *next; - struct stat st; struct dirent **fs_entries = NULL; int num_fs_entries = scandir (path, &fs_entries, 0, dirent_sort_inode); + int entry_type; int i = 0; if (num_fs_entries == -1) { @@ -742,15 +742,14 @@ count_files (const char *path, int *count, add_files_state_t *state) continue; } - stat (next, &st); - - if (S_ISREG (st.st_mode)) { + entry_type = dirent_type (path, entry); + if (entry_type == S_IFREG) { *count = *count + 1; if (*count % 1000 == 0) { printf ("Found %d files so far.\r", *count); fflush (stdout); } - } else if (S_ISDIR (st.st_mode)) { + } else if (entry_type == S_IFDIR) { count_files (next, count, state); } -- 1.8.5.2