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

Commits on Jun 26, 2024

  1. 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 <[email protected]>
    giulianobelinassi authored and OmniBlade committed Jun 26, 2024
    Configuration menu
    Copy the full SHA
    06e10b1 View commit details
    Browse the repository at this point in the history