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

Improve the for loop #22

Open
gonrial opened this issue Nov 22, 2017 · 0 comments
Open

Improve the for loop #22

gonrial opened this issue Nov 22, 2017 · 0 comments

Comments

@gonrial
Copy link

gonrial commented Nov 22, 2017

https://github.com/afilgueira/ults/blob/3fb87b6887ad80c554931dddae49ef326ebc040c/hilolay/hilolay.c#L91-L98

Alternatives:

    for (new_ult = &ults[0];new_ult->state != FREE; new_ult++) {
        if (new_ult == &ults[MAX_ULTS]) {
            lib_log("Cannot create a new ULTs!");
            return ERROR_TOO_MANY_ULTS;
        }
    }
    for (new_ult = &ults[0]; new_ult != &ults[MAX_ULTS] && new_ult->state != FREE; new_ult++);
    if (new_ult == &ults[MAX_ULTS]) {
        lib_log("Cannot create a new ULTs!");
        return ERROR_TOO_MANY_ULTS;
    }
    new_ult = &ults[0];
    while (new_ult != &ults[MAX_ULTS] && new_ult->state != FREE){
       new_ult++;
    }
    if (new_ult == &ults[MAX_ULTS]) {
        lib_log("Cannot create a new ULTs!");
        return ERROR_TOO_MANY_ULTS;
    }
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

No branches or pull requests

1 participant