From patchwork Wed Oct 17 10:08:09 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Phillip Potter X-Patchwork-Id: 10645225 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 44F8C109C for ; Wed, 17 Oct 2018 10:08:17 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 265E428906 for ; Wed, 17 Oct 2018 10:08:17 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 187AA2A925; Wed, 17 Oct 2018 10:08:17 +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=-7.9 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI 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 05A2128906 for ; Wed, 17 Oct 2018 10:08:16 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727053AbeJQSDM (ORCPT ); Wed, 17 Oct 2018 14:03:12 -0400 Received: from mail-wm1-f67.google.com ([209.85.128.67]:36931 "EHLO mail-wm1-f67.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726861AbeJQSDL (ORCPT ); Wed, 17 Oct 2018 14:03:11 -0400 Received: by mail-wm1-f67.google.com with SMTP id 185-v6so1531890wmt.2 for ; Wed, 17 Oct 2018 03:08:11 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=philpotter-co-uk.20150623.gappssmtp.com; s=20150623; h=date:from:to:cc:subject:message-id:mime-version:content-disposition :user-agent; bh=lx0cw+9rF/07CO1RshCjn2zaAnRoqJpQJvSZ7+l+DRw=; b=2Pr7LSjzhDj0BACYKlsB5/35jjRH/akXhTwsa6UMp0Nzc8IGSpZxeR4CHRTLyYcEkU p66F+8VgHEKrty/uVuldYE0JXfc+PMevT6VVutVlsBmQPLjqCH3I1HHLjhkr1ojEIVVc PVW3CE78UBqztvG/y1J71EhxbgSEsTd/n4CT0IEHxbgJaj3WviHQ4a/5QqGsB10znT8M s+cQWTKAGHRLYg2U/QAigeJ9670cC3vfRqRKAPjOw0ZeLvjEIMpZkHJK5ODNVO/IzMMX Cq5o5egv9DMVCWiCHQCOYscPuiBENr316xgbt3lmhafZlwdTfDNb1iQcqHsr0U1EP33t qxiw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:mime-version :content-disposition:user-agent; bh=lx0cw+9rF/07CO1RshCjn2zaAnRoqJpQJvSZ7+l+DRw=; b=tpP28xzdZeFWrrWdULlI4hN9K0SodBnEjORB+TAPFY7XAWecNxdQKrazPDjQoNI5fB cuidivAm4nju4DHA5QUJlBsNg7wDXvhwH98cf8ikESCs3ncozbycQaHfvvVjL7icHL6H cRQn/Sns9BKsd2jHbzHK05ZH4K6MHFpKTQJwyBOlBAraPF0O5P+bPxBF2fDLUzpGBL3i DhUKdYcrnho/I+dvyjbnhIAlLZV9lxhTUbPHqZ7BmZplwt7eldDlXfopvVHXJpXQCFNf 7vkdJcWYfpRW8aH2gllBpPtwDC7pqDraSrwFsXuvzcqlhRp2fj9g4hqh/3vTidlEsihM FrWw== X-Gm-Message-State: ABuFfogUo/ZTq5d8CeMoIQl9gO53sVS16Cd8REorrmM4yUmZtlYhQgJe FX9TUM13v6UyQQaHYLDl74+3cIB2KkAUyQ== X-Google-Smtp-Source: ACcGV62ReuRn8UFxlWuwqj8sKgRib39ILxwvvvOJ+hdAzk81sPI8AwBtcGhUNUQKkLQaHg0QQvmlYw== X-Received: by 2002:a1c:5fc2:: with SMTP id t185-v6mr2115908wmb.12.1539770891024; Wed, 17 Oct 2018 03:08:11 -0700 (PDT) Received: from pathfinder (62-64-249-96.dynamic.dsl.as9105.com. [62.64.249.96]) by smtp.gmail.com with ESMTPSA id o201-v6sm1783038wmg.16.2018.10.17.03.08.10 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Wed, 17 Oct 2018 03:08:10 -0700 (PDT) Date: Wed, 17 Oct 2018 11:08:09 +0100 From: Phillip Potter To: dushistov@mail.ru Cc: linux-kernel@vger.kernel.org, linux-fsdevel@vger.kernel.org Subject: [PATCH] fs: ufs: Remove switch statement from ufs_set_de_type function Message-ID: <20181017100809.GA9070@pathfinder> MIME-Version: 1.0 Content-Disposition: inline User-Agent: Mutt/1.10.1 (2018-07-13) Sender: linux-fsdevel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-fsdevel@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Remove switch statement from ufs_set_de_type function in fs/ufs/util.h header and replace with simple assignment. For each case, S_IFx >> 12 is equal to DT_x, so in valid cases (mode & S_IFMT) >> 12 should give us the correct file type. For invalid cases, upper layer validation catches this anyway, so this improves readability and arguably performance by assigning (mode & S_IFMT) >> 12 directly. Signed-off-by: Phillip Potter --- fs/ufs/util.h | 30 ++---------------------------- 1 file changed, 2 insertions(+), 28 deletions(-) diff --git a/fs/ufs/util.h b/fs/ufs/util.h index 1fd3011ea623..7e0c0878b9f9 100644 --- a/fs/ufs/util.h +++ b/fs/ufs/util.h @@ -16,6 +16,7 @@ * some useful macros */ #define in_range(b,first,len) ((b)>=(first)&&(b)<(first)+(len)) +#define S_SHIFT 12 /* * functions used for retyping @@ -158,34 +159,7 @@ ufs_set_de_type(struct super_block *sb, struct ufs_dir_entry *de, int mode) if ((UFS_SB(sb)->s_flags & UFS_DE_MASK) != UFS_DE_44BSD) return; - /* - * TODO turn this into a table lookup - */ - switch (mode & S_IFMT) { - case S_IFSOCK: - de->d_u.d_44.d_type = DT_SOCK; - break; - case S_IFLNK: - de->d_u.d_44.d_type = DT_LNK; - break; - case S_IFREG: - de->d_u.d_44.d_type = DT_REG; - break; - case S_IFBLK: - de->d_u.d_44.d_type = DT_BLK; - break; - case S_IFDIR: - de->d_u.d_44.d_type = DT_DIR; - break; - case S_IFCHR: - de->d_u.d_44.d_type = DT_CHR; - break; - case S_IFIFO: - de->d_u.d_44.d_type = DT_FIFO; - break; - default: - de->d_u.d_44.d_type = DT_UNKNOWN; - } + de->d_u.d_44.d_type = (mode & S_IFMT) >> S_SHIFT; } static inline u32