Skip to contentSkip to conversation

2.4.19 Generate better code for nfs_sillyrename

PATCH In review Keith Owens 2 participants 2 messages Aug 28, 2002 – Aug 31, 2002 NFS client

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 2.4.19 Generate better code for nfs_sillyrename

Using strlen() generates an unnecessary inline function expansion plus dynamic stack adjustment. For constant strings, strlen() == sizeof()-1 and the object code is better. Patch against 2.4.19.

fs/nfs/dir.c +1 -1
diff -urp 2.4.x-xfs-linux/fs/nfs/dir.c 2.4.x-xfs-linux-kdb/fs/nfs/dir.c
@@ -741,7 +741,7 @@ static int nfs_sillyrename(struct inode 
 	static unsigned int sillycounter;
 	const int      i_inosize  = sizeof(dir->i_ino)*2;
 	const int      countersize = sizeof(sillycounter)*2;
-	const int      slen       = strlen(".nfs") + i_inosize + countersize;
+	const int      slen       = sizeof(".nfs")-1 + i_inosize + countersize;
 	char           silly[slen+1];
 	struct qstr    qsilly;
 	struct dentry *sdentry;
#1 lore raw
Quoted 3 lines · Keith Owens

Using strlen() generates an unnecessary inline function expansion plus dynamic stack adjustment. For constant strings, strlen() == sizeof()-1 and the object code is better. Patch against 2.4.19.

But now the source code is worse. Macro?

Quoted 12 lines

diff -urp 2.4.x-xfs-linux/fs/nfs/dir.c 2.4.x-xfs-linux-kdb/fs/nfs/dir.c

fs/nfs/dir.c +1 -1
@@ -741,7 +741,7 @@ static int nfs_sillyrename(struct inode 
 	static unsigned int sillycounter;
 	const int      i_inosize  = sizeof(dir->i_ino)*2;
 	const int      countersize = sizeof(sillycounter)*2;
-	const int      slen       = strlen(".nfs") + i_inosize + countersize;
+	const int      slen       = sizeof(".nfs")-1 + i_inosize + countersize;
 	char           silly[slen+1];
 	struct qstr    qsilly;
 	struct dentry *sdentry;
Signature · 1 line
Daniel