mirror of
https://git.proxmox.com/git/mirror_zfs.git
synced 2026-05-22 10:37:35 +03:00
Avoid computing strlen() inside loops
Compiling with -O0 (no proper optimizations), strlen() call in loops for comparing the size, isn't being called/initialized before the actual loop gets started, which causes n-numbers of strlen() calls (as long as the string is). Keeping the length before entering in the loop is a good idea. On some places, even with -O2, both GCC and Clang can't recognize this pattern, which seem to happen in an array of char pointer. Reviewed-by: Brian Behlendorf <behlendorf1@llnl.gov> Reviewed-by: Alexander Motin <mav@FreeBSD.org> Signed-off-by: rilysh <nightquick@proton.me> Closes #16584
This commit is contained in:
+5
-2
@@ -56,6 +56,7 @@ main(int argc, const char *const *argv)
|
||||
return (1);
|
||||
}
|
||||
const char *dev_name = argv[1];
|
||||
size_t i, len;
|
||||
|
||||
int fd;
|
||||
struct stat sb;
|
||||
@@ -73,11 +74,13 @@ main(int argc, const char *const *argv)
|
||||
}
|
||||
|
||||
const char *dev_part = strrchr(dev_name, 'p');
|
||||
len = strlen(zvol_name);
|
||||
if (dev_part != NULL) {
|
||||
sprintf(zvol_name + strlen(zvol_name), "-part%s", dev_part + 1);
|
||||
sprintf(zvol_name + len, "-part%s", dev_part + 1);
|
||||
len = strlen(zvol_name);
|
||||
}
|
||||
|
||||
for (size_t i = 0; i < strlen(zvol_name); ++i)
|
||||
for (i = 0; i < len; ++i)
|
||||
if (isblank(zvol_name[i]))
|
||||
zvol_name[i] = '+';
|
||||
|
||||
|
||||
Reference in New Issue
Block a user