From patchwork Wed Jun 7 00:58:40 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Timofey Titovets X-Patchwork-Id: 9770385 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 06B7960393 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 DD4272853C for ; Wed, 7 Jun 2017 01:00:18 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id D1D2628539; Wed, 7 Jun 2017 01:00:18 +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 6D745269A3 for ; Wed, 7 Jun 2017 01:00:18 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751495AbdFGBAI (ORCPT ); Tue, 6 Jun 2017 21:00:08 -0400 Received: from mail-wr0-f193.google.com ([209.85.128.193]:33970 "EHLO mail-wr0-f193.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751453AbdFGBAG (ORCPT ); Tue, 6 Jun 2017 21:00:06 -0400 Received: by mail-wr0-f193.google.com with SMTP id u101so9096086wrc.1 for ; Tue, 06 Jun 2017 18:00:05 -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=QGg1nMmakAtjlXaTdl03McD4ZLmmH1qCbxwSfbW3FmQ=; b=jUbCiB5XQmiNlNF7adznWh/M75ECnPe96Vd9bRvzod6nKmU3Kptyx2UPWkpZsil38x AG1q/GsyRkBshR/hFXaik2K+AHSGAcN1bWdzF4s2lWxGvlWaoJDRLEs+/l4xqOW3TwsF N8yzXrhvSJOg36QjfWVjLfYcTft98f4SIAb+gsEgM54kGBU+qyj5QDZxa3IU0XJOh/ya 9evRCW59xt8OG1DVT1eIoMJ3+z6YssvaLJpTadM9Hv8BfoMHlKP1/qzENLvqNWCYLl5Y 39EQOuMW475FRzx33cD5/LEJw4ZNkRpC+rp3xLvDPgCAgfEmSKa8p62fyx+hDvPJHCCP TdTw== 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=QGg1nMmakAtjlXaTdl03McD4ZLmmH1qCbxwSfbW3FmQ=; b=P1kvzy+G+ZMsMUf1u4VNZ3y5k4Zn0JTEUX96O0tBzhwf/XAuUaUmUN7K/H8gnzqoq0 lE9lXYVWytln0mZT2xqM2nWc7r8h38FJ/lnqrTeM4NfY26E6rjBeFmlJfh5g+H0IE7Vj OQxKOkSoXU4/CvNajcZLe8f85iHWuY+fQuPQEoYmbl23taMDwl5O4k/f6kYzWcq9iURU QDo1erwhneqKk9AMnVR1GE52BC91slICrSQaoqJ8nZhg4A5HMS51WN9TtltStVAYLY9G bmeiMIqEP89T31Qtp6qj1p0v5HGTxpF7L857VW1MdD8INDQej28IFwiGVhk1YlinkoZV ItEA== X-Gm-Message-State: AODbwcDiWndRuLW04j9SNBqVSu+NVBUgB1Gjn/ZvIo7pP/DipS4A2lHn CxewGDHBMYCyDJ1h X-Received: by 10.223.168.2 with SMTP id l2mr19483722wrc.94.1496797204474; Tue, 06 Jun 2017 18:00:04 -0700 (PDT) Received: from localhost.localdomain ([91.215.176.151]) by smtp.gmail.com with ESMTPSA id q16sm338101wmg.2.2017.06.06.18.00.03 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 06 Jun 2017 18:00:04 -0700 (PDT) From: Timofey Titovets To: linux-btrfs@vger.kernel.org Cc: Timofey Titovets Subject: [PATCH 3/7] Btrfs: ref_node_cmp decrease max compare count Date: Wed, 7 Jun 2017 03:58:40 +0300 Message-Id: <20170607005844.2078-4-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 8 comparison, just add some new checks to switch check branch faster now in worst case code do 5 comparison Signed-off-by: Timofey Titovets --- fs/btrfs/backref.c | 28 ++++++++++++++++------------ 1 file changed, 16 insertions(+), 12 deletions(-) diff --git a/fs/btrfs/backref.c b/fs/btrfs/backref.c index 24865da63..2e4709e0c 100644 --- a/fs/btrfs/backref.c +++ b/fs/btrfs/backref.c @@ -120,25 +120,29 @@ static void ref_root_free(struct ref_root *ref_tree) */ static int ref_node_cmp(struct ref_node *a, struct ref_node *b) { - if (a->root_id < b->root_id) - return -1; - else if (a->root_id > b->root_id) + if (a->root_id != b->root_id) { + if (a->root_id < b->root_id) + return -1; return 1; + } - if (a->object_id < b->object_id) - return -1; - else if (a->object_id > b->object_id) + if (a->object_id != b->object_id) { + if (a->object_id < b->object_id) + return -1; return 1; + } - if (a->offset < b->offset) - return -1; - else if (a->offset > b->offset) + if (a->offset != b->offset) { + if (a->offset < b->offset) + return -1; return 1; + } - if (a->parent < b->parent) - return -1; - else if (a->parent > b->parent) + if (a->parent != b->parent) { + if (a->parent < b->parent) + return -1; return 1; + } return 0; }