|
|
|
|
|
by BoppreH
1073 days ago
|
|
You can also use math to avoid most of the jumps: int run_switches(char *input) {
int res = 0;
while (true) {
char c = *input++;
if (c == '\0') return res;
// Here's the trick:
res += (c == 's') - (c == 'p');
}
}
This gives a 3.7x speed compared to loop-1.c. The lower line count is also nice. |
|