aboutsummaryrefslogtreecommitdiff
path: root/optimize.md
blob: b2418ef167b2272f0e1c58abb9662432e85cf3ad (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
Turn ['a', 'i', 'u', 'e', 'o'].contains(c) into:

1 - inline:
char arr[] = { 'a', 'i', 'u', 'e', 'o' };
for(int i = 0; i < 5; ++i) {
    if(arr[i] == c)
        return true;
}
return false;

2 - constant loop unrolling:
if('a' == c)
    return true;
if('i' == c)
    return true;
if('u' == c)
    return true;
if('e' == c)
    return true;
if('o' == c)
    return true;
return false;

3 - multiple comparisons to same variable turned into a switch:
switch(c) {
    case 'a':
    case 'i':
    case 'u':
    case 'e':
    case 'o':
        return true;
}
return false;