* [PATCH v2] fs/ufs: refactor ufs_set_de_type in util.h to use a table lookup
@ 2026-03-31 19:52 Daniil Bulgar
0 siblings, 0 replies; only message in thread
From: Daniil Bulgar @ 2026-03-31 19:52 UTC (permalink / raw)
To: linux-kernel; +Cc: linux-fsdevel, Daniil Bulgar
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
^ permalink raw reply [flat|nested] only message in thread
only message in thread, other threads:[~2026-03-31 19:55 UTC | newest]
Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-03-31 19:52 [PATCH v2] fs/ufs: refactor ufs_set_de_type in util.h to use a table lookup Daniil Bulgar
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®