mirror of
https://git.proxmox.com/git/mirror_zfs.git
synced 2026-05-24 11:18:52 +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
-3
@@ -685,15 +685,17 @@ static int
|
||||
str2shift(const char *buf)
|
||||
{
|
||||
const char *ends = "BKMGTPEZ";
|
||||
int i;
|
||||
int i, len;
|
||||
|
||||
if (buf[0] == '\0')
|
||||
return (0);
|
||||
for (i = 0; i < strlen(ends); i++) {
|
||||
|
||||
len = strlen(ends);
|
||||
for (i = 0; i < len; i++) {
|
||||
if (toupper(buf[0]) == ends[i])
|
||||
break;
|
||||
}
|
||||
if (i == strlen(ends)) {
|
||||
if (i == len) {
|
||||
(void) fprintf(stderr, "ztest: invalid bytes suffix: %s\n",
|
||||
buf);
|
||||
usage(B_FALSE);
|
||||
|
||||
Reference in New Issue
Block a user