y-flat / yfc

The best (because it's the only) compiler for the Y-flat programming language.
GNU General Public License v3.0
6 stars 7 forks source link

Factor out common list looping pattern #94

Closed adamhutchings closed 2 years ago

adamhutchings commented 2 years ago

The most common list looping pattern is:

for (;;) {
        if (yf_list_get(&some_list, (void **) &some_element) == -1) break;
        if (!some_element) break; // this only sometimes
        // actually do code
        yf_list_next(&node->params);
    }

Refactor it so it fits into a for loop header like:

for (yf_list_reset(&some_list); yf_in_list(&some_list); yf_list_get(&some_list, &some_element)) {
        // actually do code
}