Skip to content

Commit c8fbf51

Browse files
committed
perf: optimize sanitise_LinkTable string loop
Eliminate O(N^2) overhead in sanitise_LinkTable by replacing strlen() with a null-terminator check in the loop condition. Co-authored-by: fangfufu <2323403+fangfufu@users.noreply.github.com>
1 parent 26db6fc commit c8fbf51

1 file changed

Lines changed: 1 addition & 1 deletion

File tree

src/sonic.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -319,7 +319,7 @@ static void sanitise_LinkTable(LinkTable *linktbl)
319319
strcpy(linktbl->links[i]->linkname, "__FORWARD-SLASH__");
320320
}
321321

322-
for (size_t j = 0; j < strlen(linktbl->links[i]->linkname); j++) {
322+
for (size_t j = 0; linktbl->links[i]->linkname[j] != '\0'; j++) {
323323
if (linktbl->links[i]->linkname[j] == '/') {
324324
linktbl->links[i]->linkname[j] = '-';
325325
}

0 commit comments

Comments
 (0)