From nobody Tue Dec 2 02:43:48 2025 Received: from mail-pj1-f46.google.com (mail-pj1-f46.google.com [209.85.216.46]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id D64391D2F42 for ; Tue, 18 Nov 2025 02:36:10 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.216.46 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1763433372; cv=none; b=rfGGUTUjtozDRag0KuK7HvNAK0qNAdsfHT796tVzMK8a8KZ/FB8eODvKjsZf8IGyTnlhWRiaK4V8/d7ALoTVlglr4L/tJ5wpClu4nbZ4OIp4jOpSxOp6TpXODwvDEGiuWLala8yH1SvD+ejIZ0nYXUZXqtY7cGb+QQk2+b/d9NI= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1763433372; c=relaxed/simple; bh=B9gxuy9BzkcGTPPMSutOS745DgnJf5De1V8vCTMSzhA=; h=From:To:Cc:Subject:Date:Message-Id:MIME-Version; b=o8wknXfxBhZwvcLigYiHbV9HKtOsQDkCWIvp0I+309+LjBvQO/KL3SKf584MxvY1KKXDkV4IhRo3NZ7V5mV/qMmHZhLvlYTajDXE8jBIdlptimm0FLMvCJS5IFRb4QF3ipd8hMsPr/X4vbWnn3YLYuceFIhlAoYxbDX5qruxhZY= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=ee.vjti.ac.in; spf=none smtp.mailfrom=ee.vjti.ac.in; dkim=pass (1024-bit key) header.d=vjti.ac.in header.i=@vjti.ac.in header.b=OTXVrULW; arc=none smtp.client-ip=209.85.216.46 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=ee.vjti.ac.in Authentication-Results: smtp.subspace.kernel.org; spf=none smtp.mailfrom=ee.vjti.ac.in Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=vjti.ac.in header.i=@vjti.ac.in header.b="OTXVrULW" Received: by mail-pj1-f46.google.com with SMTP id 98e67ed59e1d1-3434700be69so6676359a91.1 for ; Mon, 17 Nov 2025 18:36:10 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=vjti.ac.in; s=google; t=1763433370; x=1764038170; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=OYu2RhnZVYmXMaI97bqasjUTQTxZCRBVWCCZq8Qh5H8=; b=OTXVrULWeGRxUH/zE31yqqkpdVzL0jQ66deHGa//aqJMVkuCX5daJM7wowa9ph4sJw KIC8JwNRw6ChsIw5xzv0pinCFSspQhSO2iAXOXfoCG0l2NdVskXzA0clv5FOlCmY3B3a uQetYb0SJRpiphARBknJlomC4mnwcOP6O0Kf4= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1763433370; x=1764038170; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-gg:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=OYu2RhnZVYmXMaI97bqasjUTQTxZCRBVWCCZq8Qh5H8=; b=Gl8Zyn4gsp8f/FOajsoKu/c+2e0AKP7gXuejoqyRarLQlxd2hbSd7Jvfu9vbvhDpOh bRqDkpxiAkt8rCDLa8B/ZtZjfQtRtFhrrqKYl8sfDgwQlDA5lmp9xSlGW8CExIXe+sZ3 g3+ZWhwhFRbgJgiDIKkyJY22GCdNTBWNm/gKrC7XkDxO1X06VVuHMPA2NRPtzyxvmK6V mZb5RSJMNYOkl/cK9buHuE/f+N/+2j15oJU0yn1P37r3qCFTkXa6XdoHOxPpM/bRqpBX Hmy5srXl1dx7UMhVnrr3HmR87+n1HET7bRpEy9cCnehChk0FfY6yrDevcSYP7SU4sFpY ui9Q== X-Gm-Message-State: AOJu0Yy5vyGKiBHsubsZ3hoH+MtKYvQsBtyPuox7XzNXhaNr0ZrYI7Qg MmPZJHP2P1TTbhXjS6U53/sLjphcGQ0M7NbVm1umg31Y/wft2gDn5GtiaPw3pBVP3qGecGPMC4q Iih3XOBzKbQ== X-Gm-Gg: ASbGncuLBm2Z9ZsXGKvJ85IqRx+vUnSAO9xQb9YV4TEcgnCVeklmScY3hfL0BNSbjmX sf3DYVYKzuz4XQtAif5/UFC+jJrR8WCh46vB3tSsH3LLJJS776QZNQZI5Kcbn4HzwSAJgjMBoFv AoIL7ER/A5q6etlFMUBsc4WQHuIeXo+bRmhbUjf3FvGCoBJDL/Sll5P1QQWw+AUoqkNsrZU8PIt 9KiP4o1tRmYpKrpDBKB59lSpPVe+hVfUMSwa7+hhZ8bM+zZTxpd2J0PBfubScY6jw2CuT+98jky eI8awUlduRzEnm244U1nJQsYL5OFpGZcWINVQVuLA2EHEAS4kp/5uH3vSuozDmK0g4eQ81uqc3x Qpd3vEU4oM8kz9mMSHHcdAuOs9z2imrbbCYrn6ij/Esl02RNKo84qu1VuSoaIXB+VmyTpYEFtVb Gn87CcxU6d3VSkKl02chXhfsFYAXt6Gz74mzJpEVJYfa6vb3/Mfj0WsE2Aw6+H82L8nIUOlIZFG pbeRg== X-Google-Smtp-Source: AGHT+IEjwhapqC757GMhn2dIE25PtiFVzX+Oqr0lsE89b1ciWb8Fo/ED33MCCT6w/BiL4EuodD8vTQ== X-Received: by 2002:a17:90b:5684:b0:340:e517:4e05 with SMTP id 98e67ed59e1d1-343f9ea3115mr18765496a91.12.1763433369855; Mon, 17 Nov 2025 18:36:09 -0800 (PST) Received: from ranegod-HP-ENVY-x360-Convertible-13-bd0xxx.. ([2405:201:31:d869:1d97:5820:9ba5:7a5d]) by smtp.gmail.com with ESMTPSA id 98e67ed59e1d1-3456513f162sm11008196a91.8.2025.11.17.18.36.07 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 17 Nov 2025 18:36:09 -0800 (PST) From: ssrane_b23@ee.vjti.ac.in X-Google-Original-From: ssranevjti@gmail.com To: linux-kernel@vger.kernel.org Cc: daniel.pirkl@email.cz, dushistov@mail.ru, Shaurya Rane Subject: [PATCH] fs/ufs: optimize ufs_set_de_type() with lookup table Date: Tue, 18 Nov 2025 08:06:02 +0530 Message-Id: <20251118023602.15544-1-ssranevjti@gmail.com> X-Mailer: git-send-email 2.34.1 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" From: Shaurya Rane 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 --- 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] =3D { + [0] =3D DT_UNKNOWN, + [1] =3D DT_FIFO, + [2] =3D DT_CHR, + [3] =3D DT_UNKNOWN, + [4] =3D DT_DIR, + [5] =3D DT_UNKNOWN, + [6] =3D DT_BLK, + [7] =3D DT_UNKNOWN, + [8] =3D DT_REG, + [9] =3D DT_UNKNOWN, + [10] =3D DT_LNK, + [11] =3D DT_UNKNOWN, + [12] =3D DT_SOCK, + [13] =3D DT_UNKNOWN, + [14] =3D DT_UNKNOWN, + [15] =3D DT_UNKNOWN, + }; + if ((UFS_SB(sb)->s_flags & UFS_DE_MASK) !=3D 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 =3D DT_SOCK; - break; - case S_IFLNK: - de->d_u.d_44.d_type =3D DT_LNK; - break; - case S_IFREG: - de->d_u.d_44.d_type =3D DT_REG; - break; - case S_IFBLK: - de->d_u.d_44.d_type =3D DT_BLK; - break; - case S_IFDIR: - de->d_u.d_44.d_type =3D DT_DIR; - break; - case S_IFCHR: - de->d_u.d_44.d_type =3D DT_CHR; - break; - case S_IFIFO: - de->d_u.d_44.d_type =3D DT_FIFO; - break; - default: - de->d_u.d_44.d_type =3D DT_UNKNOWN; - } + de->d_u.d_44.d_type =3D ifmt_to_dt[(mode & S_IFMT) >> 12]; } static inline u32 -- 2.34.1