Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Replace strlen upper bound with checks for '\0' #1018

Merged
merged 1 commit into from
Jun 26, 2024

Conversation

giulianobelinassi
Copy link
Collaborator

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 than this, as it will call strlen for each character of the string, which is O(n ²) instead of O(n), where n = size of string. Replace those cases as well.

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 <[email protected]>
@OmniBlade OmniBlade merged commit 8000d0a into TheAssemblyArmada:vanilla Jun 26, 2024
17 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants