File tree Expand file tree Collapse file tree 1 file changed +63
-0
lines changed Expand file tree Collapse file tree 1 file changed +63
-0
lines changed Original file line number Diff line number Diff line change
1
+ # Optimizations
2
+
3
+ Expr has a bunch of optimization which will produce more optimal program during compile step.
4
+
5
+ ## In array
6
+
7
+ ``` js
8
+ value in [' foo' , ' bar' , ' baz' ]
9
+ ```
10
+
11
+ If expr finds an ` in ` or ` not in ` expression with an array, it will be transformed into:
12
+
13
+ ``` js
14
+ value in {" foo" : true , " bar" : true , " baz" : true }
15
+ ```
16
+
17
+ ## Constant folding
18
+
19
+ Arithmetic expressions with constants is computed on compile step and replaced with result.
20
+
21
+ ``` js
22
+ - (2 - 5 )** 3 - 2 / (+ 4 - 3 )+- 2
23
+ ```
24
+
25
+ Will be compiled to just single number:
26
+
27
+ ``` js
28
+ 23
29
+ ```
30
+
31
+ So in expressions it's safe to use some arithmetics for better readability:
32
+
33
+ ``` js
34
+ percentage > 0.3 * 100
35
+ ```
36
+
37
+ As it will be simpified to:
38
+
39
+ ``` js
40
+ percentage > 30
41
+ ```
42
+
43
+ ## In range
44
+
45
+ ``` js
46
+ user .Age in 18..32
47
+ ```
48
+
49
+ Will be replaced with binary operator:
50
+
51
+ ``` js
52
+ 18 <= user .Age && user .Age <= 32
53
+ ```
54
+
55
+ ` not in ` operator will also work.
56
+
57
+ ## Const range
58
+
59
+ ``` js
60
+ 1..10_000
61
+ ```
62
+
63
+ Ranges computed on compile stage, repleced with preallocated slices.
You can’t perform that action at this time.
0 commit comments