From: ssrane_b23@ee.vjti.ac.in
To: linux-kernel@vger.kernel.org
Cc: daniel.pirkl@email.cz, dushistov@mail.ru,
Shaurya Rane <ssrane_b23@ee.vjti.ac.in>
Subject: [PATCH] fs/ufs: optimize ufs_set_de_type() with lookup table
Date: Tue, 18 Nov 2025 08:06:02 +0530 [thread overview]
Message-ID: <20251118023602.15544-1-ssranevjti@gmail.com> (raw)
From: Shaurya Rane <ssrane_b23@ee.vjti.ac.in>
Replace the switch statement in ufs_set_de_type() with a static lookup
table as suggested by the existing TODO comment.
This optimization converts the case-by-case comparisons into a simple
array access. The implementation relies on the S_IFMT file type constants
having predictable bit patterns residing in the high bits (12-15).
By masking the mode and shifting right by 12 bits ((mode & S_IFMT) >> 12),
we obtain compact indices (0-15) that map directly to the DT_ constants:
S_IFIFO (0010000) -> index 1 -> DT_FIFO
S_IFCHR (0020000) -> index 2 -> DT_CHR
S_IFDIR (0040000) -> index 4 -> DT_DIR
S_IFBLK (0060000) -> index 6 -> DT_BLK
S_IFREG (0100000) -> index 8 -> DT_REG
S_IFLNK (0120000) -> index 10 -> DT_LNK
S_IFSOCK (0140000) -> index 12 -> DT_SOCK
All other indices map to DT_UNKNOWN (0), maintaining identical logic to
the original default case.
Signed-off-by: Shaurya Rane <ssrane_b23@ee.vjti.ac.in>
---
fs/ufs/util.h | 48 ++++++++++++++++++++----------------------------
1 file changed, 20 insertions(+), 28 deletions(-)
diff --git a/fs/ufs/util.h b/fs/ufs/util.h
index 391bb4f11d74..eef8fed133db 100644
--- a/fs/ufs/util.h
+++ b/fs/ufs/util.h
@@ -149,37 +149,29 @@ ufs_set_de_namlen(struct super_block *sb, struct ufs_dir_entry *de, u16 value)
static inline void
ufs_set_de_type(struct super_block *sb, struct ufs_dir_entry *de, int mode)
{
+ static const unsigned char ifmt_to_dt[16] = {
+ [0] = DT_UNKNOWN,
+ [1] = DT_FIFO,
+ [2] = DT_CHR,
+ [3] = DT_UNKNOWN,
+ [4] = DT_DIR,
+ [5] = DT_UNKNOWN,
+ [6] = DT_BLK,
+ [7] = DT_UNKNOWN,
+ [8] = DT_REG,
+ [9] = DT_UNKNOWN,
+ [10] = DT_LNK,
+ [11] = DT_UNKNOWN,
+ [12] = DT_SOCK,
+ [13] = DT_UNKNOWN,
+ [14] = DT_UNKNOWN,
+ [15] = DT_UNKNOWN,
+ };
+
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 = ifmt_to_dt[(mode & S_IFMT) >> 12];
}
static inline u32
--
2.34.1
reply other threads:[~2025-11-18 2:36 UTC|newest]
Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20251118023602.15544-1-ssranevjti@gmail.com \
--to=ssrane_b23@ee.vjti.ac.in \
--cc=daniel.pirkl@email.cz \
--cc=dushistov@mail.ru \
--cc=linux-kernel@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®