aboutsummaryrefslogtreecommitdiff
path: root/optimize.md
diff options
context:
space:
mode:
Diffstat (limited to 'optimize.md')
-rw-r--r--optimize.md33
1 files changed, 33 insertions, 0 deletions
diff --git a/optimize.md b/optimize.md
new file mode 100644
index 0000000..b2418ef
--- /dev/null
+++ b/optimize.md
@@ -0,0 +1,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;