Skip to content

Commit 2e66a83

Browse files
committed
Add comment to allocation gather transform
1 parent 2b13dc1 commit 2e66a83

1 file changed

Lines changed: 52 additions & 0 deletions

File tree

Src/FastData/Generators/EarlyExits/AllocationGatherTransform.cs

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,58 @@ namespace Genbox.FastData.Generators.EarlyExits;
77

88
public class AllocationGatherTransform : IExprTransform
99
{
10+
/*
11+
If we just print out each expression, we will get something like this:
12+
13+
public bool Contains(string key)
14+
{
15+
if (GetLength(key) < 3 || GetLength(key) > 6)
16+
return false;
17+
18+
if (GetFirstChar(key) != 'Æ')
19+
return false;
20+
21+
if (GetFirstChar(key) < 'A')
22+
return false;
23+
}
24+
25+
That's suboptimal for performance due to repeated calls. However, if we just detect the calls and print them out in the beginning, it is
26+
still not good, as the allocations will happen before they are needed.
27+
28+
public bool Contains(string key)
29+
{
30+
uint len = GetLength(key);
31+
char firstChar = GetFirstChar(key);
32+
33+
if (len < 3 || len > 6)
34+
return false;
35+
36+
if (firstChar != 'Æ')
37+
return false;
38+
39+
if (firstChar < 'A')
40+
return false;
41+
}
42+
43+
However, by adding the gatherer transform, it will register the allocation the first time they are needed, and it now looks like this:
44+
45+
public bool Contains(string key)
46+
{
47+
uint len = GetLength(key);
48+
49+
if (len < 3 || len > 6)
50+
return false;
51+
52+
char firstChar = GetFirstChar(key);
53+
54+
if (firstChar != 'Æ')
55+
return false;
56+
57+
if (firstChar < 'A')
58+
return false;
59+
}
60+
*/
61+
1062
public object CreateState() => new AllocationGatherState();
1163

1264
public IEnumerable<AnnotatedExpr> Transform(AnnotatedExpr expr, object state)

0 commit comments

Comments
 (0)