-
Notifications
You must be signed in to change notification settings - Fork 55
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Replace strlen upper bound with checks for '\0'
Strings in C are always terminated by the '\0' character. We can explore this to avoid sweeping through the string twice. Constructs like `for (i = 0; i < strlen(str); i++)` are even worse, as it will call strlen **for each character of the string**, which is O(n²) instead of O(n). Replace those cases as well. Signed-off-by: Giuliano Belinassi <gbelinassi@suse.de>
- Loading branch information
1 parent
dbfebf3
commit 8000d0a
Showing
2 changed files
with
15 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters