From patchwork Wed Jun 7 00:58:39 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Timofey Titovets X-Patchwork-Id: 9770393 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id E104860353 for ; Wed, 7 Jun 2017 01:00:19 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id C382128542 for ; Wed, 7 Jun 2017 01:00:19 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id C1E4C2854E; Wed, 7 Jun 2017 01:00:19 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.8 required=2.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED, FREEMAIL_FROM, RCVD_IN_DNSWL_HI, T_DKIM_INVALID autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 4BBAB27E63 for ; Wed, 7 Jun 2017 01:00:18 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751478AbdFGBAG (ORCPT ); Tue, 6 Jun 2017 21:00:06 -0400 Received: from mail-wr0-f196.google.com ([209.85.128.196]:35633 "EHLO mail-wr0-f196.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751436AbdFGBAF (ORCPT ); Tue, 6 Jun 2017 21:00:05 -0400 Received: by mail-wr0-f196.google.com with SMTP id g76so11546712wrd.2 for ; Tue, 06 Jun 2017 18:00:04 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=yIa/nud6+Xx8q8jZj4qpCQfpiw2lY6jOU+SzzAojqF4=; b=jTNeDvg9QETomBdx0n9Z6icVoIXZM02uDuBZ57j4FFOHinP6HofO0hfeFaAYm9hyR9 HFZAGnWwTvss4HspyPcDr2cy5Lj5TyzfiOHGqzWmfzHr/e8QUS/m1DnQb/2lRt/WuIWZ GE6LqeUZ5B/evi/k55r2ARS9vGRds6cRt+/WTUiWY0iyBxviq+x25dASc0EGaK4USkPm mppls2SitKcQWHnTNu15lFDJdGEPqTAha0sftDaoCEI6CfJnKSIv0A3fnVr9mBDjriU8 /j3e7pWeGbG/ZaF2kSetcoIWAPDIePlTiGWtUFVtrwzpwTBiV0XyXOX9xguAQSU/KMBw gZtQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=yIa/nud6+Xx8q8jZj4qpCQfpiw2lY6jOU+SzzAojqF4=; b=VXdcb6h1lQN/yMrFgtQFnZ8y33Dk71+PJLF23haiyw5+0s1YoJMAVAbgjK7YWvvSAX rHIwzXlE/q9gFA39yUieOuAUt7de5uBCrW2zcEDLHqP/PrFSHfrJbAFbwmTN+/4lTcWw EZmIeAHkBjG1byVLmvFQkfpm4Fm/9vxGbLRWL/BNfwgiBZl5dKz40cTSwGqNlyrwA5KM VV5glEM0zr4bMiyxKaElkZ8caSac8QVUZRHg4OmxeJbmjDcnYmoXLo2B9XPbLBL0T2Yg S4Z2d/dQEbOboumcyz5RGNQcFegqla+kFOR1YSLwicCm8kahz7JSXWbryE9nQITGdgDP 8acw== X-Gm-Message-State: AODbwcBL5Umf3MjfxjenLPJB9u7jJqzpzO9OdxVe9blXlXcfTlDusCWg 71ch6Cd1TH0GIeJJ X-Received: by 10.223.146.166 with SMTP id 35mr19055346wrn.98.1496797203635; Tue, 06 Jun 2017 18:00:03 -0700 (PDT) Received: from localhost.localdomain ([91.215.176.151]) by smtp.gmail.com with ESMTPSA id q16sm338101wmg.2.2017.06.06.18.00.02 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 06 Jun 2017 18:00:03 -0700 (PDT) From: Timofey Titovets To: linux-btrfs@vger.kernel.org Cc: Timofey Titovets Subject: [PATCH 2/7] Btrfs: backref_comp decrease max compare count Date: Wed, 7 Jun 2017 03:58:39 +0300 Message-Id: <20170607005844.2078-3-nefelim4ag@gmail.com> X-Mailer: git-send-email 2.13.0 In-Reply-To: <20170607005844.2078-1-nefelim4ag@gmail.com> References: <20170607005844.2078-1-nefelim4ag@gmail.com> Sender: linux-btrfs-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-btrfs@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP In worst case code do 6 comparison, just add some new checks to switch check branch faster now in worst case code do 4 comparison Signed-off-by: Timofey Titovets --- fs/btrfs/inode.c | 21 ++++++++++++--------- 1 file changed, 12 insertions(+), 9 deletions(-) diff --git a/fs/btrfs/inode.c b/fs/btrfs/inode.c index 17cbe9306..fa024642a 100644 --- a/fs/btrfs/inode.c +++ b/fs/btrfs/inode.c @@ -2249,20 +2249,23 @@ struct new_sa_defrag_extent { static int backref_comp(struct sa_defrag_extent_backref *b1, struct sa_defrag_extent_backref *b2) { - if (b1->root_id < b2->root_id) - return -1; - else if (b1->root_id > b2->root_id) + if (b1->root_id != b2->root_id) { + if (b1->root_id < b2->root_id) + return -1; return 1; + } - if (b1->inum < b2->inum) - return -1; - else if (b1->inum > b2->inum) + if (b1->inum != b2->inum) { + if (b1->inum < b2->inum) + return -1; return 1; + } - if (b1->file_pos < b2->file_pos) - return -1; - else if (b1->file_pos > b2->file_pos) + if (b1->file_pos != b2->file_pos) { + if (b1->file_pos < b2->file_pos) + return -1; return 1; + } /* * [------------------------------] ===> (a range of space)