From patchwork Thu May 19 02:54:39 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Qu Wenruo X-Patchwork-Id: 9123581 Return-Path: X-Original-To: patchwork-linux-btrfs@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork1.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork1.web.kernel.org (Postfix) with ESMTP id 886E59F1C1 for ; Thu, 19 May 2016 02:55:00 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 946762022A for ; Thu, 19 May 2016 02:54:59 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id B6F6E2021F for ; Thu, 19 May 2016 02:54:58 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752316AbcESCyy (ORCPT ); Wed, 18 May 2016 22:54:54 -0400 Received: from cn.fujitsu.com ([222.73.24.84]:39836 "EHLO song.cn.fujitsu.com" rhost-flags-OK-FAIL-OK-OK) by vger.kernel.org with ESMTP id S1751578AbcESCyy (ORCPT ); Wed, 18 May 2016 22:54:54 -0400 X-IronPort-AV: E=Sophos;i="5.20,367,1444665600"; d="scan'208";a="491045" Received: from unknown (HELO cn.fujitsu.com) ([10.167.250.3]) by song.cn.fujitsu.com with ESMTP; 19 May 2016 10:54:42 +0800 Received: from adam-work.localdomain (unknown [10.167.226.34]) by cn.fujitsu.com (Postfix) with ESMTP id 23C344056401; Thu, 19 May 2016 10:54:41 +0800 (CST) From: Qu Wenruo To: linux-btrfs@vger.kernel.org, dsterba@suse.cz Subject: [PATCH] btrfs-progs: Return earlier for previous item Date: Thu, 19 May 2016 10:54:39 +0800 Message-Id: <1463626479-7628-1-git-send-email-quwenruo@cn.fujitsu.com> X-Mailer: git-send-email 2.8.2 MIME-Version: 1.0 X-yoursite-MailScanner-ID: 23C344056401.A838E X-yoursite-MailScanner: Found to be clean X-yoursite-MailScanner-From: quwenruo@cn.fujitsu.com X-Spam-Status: No, score=-8.3 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_HI, RP_MATCHES_RCVD, UNPARSEABLE_RELAY autolearn=ham version=3.3.1 Sender: linux-btrfs-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-btrfs@vger.kernel.org X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Follow kernel code to return earlier for btrfs_previous_item() function. Before this patch, btrfs_previous_item() doesn't use its min_objectid to exit, this makes caller to check key to exit, and if caller doesn't check, it will iterate all previous item. This patch will check min_objectid and type, to early return and save some time. Signed-off-by: Qu Wenruo --- ctree.c | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/ctree.c b/ctree.c index 079696e..a98ad18 100644 --- a/ctree.c +++ b/ctree.c @@ -2880,6 +2880,7 @@ int btrfs_previous_item(struct btrfs_root *root, { struct btrfs_key found_key; struct extent_buffer *leaf; + u32 nritems; int ret; while(1) { @@ -2891,9 +2892,20 @@ int btrfs_previous_item(struct btrfs_root *root, path->slots[0]--; } leaf = path->nodes[0]; + nritems = btrfs_header_nritems(leaf); + if (nritems == 0) + return 1; + if (path->slots[0] == nritems) + path->slots[0]--; + btrfs_item_key_to_cpu(leaf, &found_key, path->slots[0]); + if (found_key.objectid < min_objectid) + break; if (found_key.type == type) return 0; + if (found_key.objectid == min_objectid && + found_key.type < type) + break; } return 1; }