From: Daniil Bulgar <bulgardaniil18@gmail.com>
To: linux-kernel@vger.kernel.org
Cc: linux-fsdevel@vger.kernel.org, Daniil Bulgar <bulgardaniil18@gmail.com>
Subject: [PATCH v2] fs/ufs: refactor ufs_set_de_type in util.h to use a table lookup
Date: Tue, 31 Mar 2026 21:52:58 +0200 [thread overview]
Message-ID: <20260331195258.71494-1-bulgardaniil18@gmail.com> (raw)
Replace the switch-case logic with a more efficient table lookup for
converting mode bits to directory entry types.
This addresses an explicit TODO in the code.
The change reduces code complexity and slightly decreases the
compiled size of the function by replacing
branching logic with a constant 16-byte array.
Signed-off-by: Daniil Bulgar <bulgardaniil18@gmail.com>
---
Changes in v2: added missing [PATCH] prefix to the subject.
fs/ufs/util.h | 39 +++++++++++----------------------------
1 file changed, 11 insertions(+), 28 deletions(-)
diff --git a/fs/ufs/util.h b/fs/ufs/util.h
index 391bb4f11..8966c3ab5 100644
--- a/fs/ufs/util.h
+++ b/fs/ufs/util.h
@@ -152,34 +152,17 @@ 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;
- }
+ static const unsigned char type_table[16] = {
+ [S_IFSOCK >> 12] = DT_SOCK,
+ [S_IFLNK >> 12] = DT_LNK,
+ [S_IFREG >> 12] = DT_REG,
+ [S_IFBLK >> 12] = DT_BLK,
+ [S_IFDIR >> 12] = DT_DIR,
+ [S_IFCHR >> 12] = DT_CHR,
+ [S_IFIFO >> 12] = DT_FIFO,
+ };
+
+ de->d_u.d_44.d_type = type_table[(mode & S_IFMT) >> 12];
}
static inline u32
--
2.53.0
reply other threads:[~2026-03-31 19:55 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=20260331195258.71494-1-bulgardaniil18@gmail.com \
--to=bulgardaniil18@gmail.com \
--cc=linux-fsdevel@vger.kernel.org \
--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®