Skip to content

Commit c7466e3

Browse files
committed
Change how constant maps are emitted. This returns to the 'optimization' that exists in the JVM version. A tiny bit slower, maybe, but decrease in memory usage.
1 parent c932cc5 commit c7466e3

File tree

1 file changed

+4
-19
lines changed

1 file changed

+4
-19
lines changed

Clojure/Clojure/CljCompiler/Ast/MapExpr.cs

Lines changed: 4 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -77,32 +77,17 @@ public static Expr Parse(ParserContext pcon, IPersistentMap form)
7777

7878
if (form is IObj iobjForm && iobjForm.meta() != null)
7979
return Compiler.OptionallyGenerateMetaInit(pcon, form, ret);
80-
//else if (constant)
81-
//{
82-
// This 'optimzation' works, mostly, unless you have nested map values.
83-
// The nested map values do not participate in the constants map, so you end up with the code to create the keys.
84-
// Result: huge duplication of keyword creation. 3X increase in init time to the REPL.
85-
// //IPersistentMap m = PersistentHashMap.EMPTY;
86-
// //for (int i = 0; i < keyvals.length(); i += 2)
87-
// // m = m.assoc(((LiteralExpr)keyvals.nth(i)).Val, ((LiteralExpr)keyvals.nth(i + 1)).Val);
88-
// //return new ConstantExpr(m);
89-
// return ret;
90-
//}
9180
else if (keysConstant)
9281
{
9382
// TBD: Add more detail to exception thrown below.
9483
if (!allConstantKeysUnique)
9584
throw new ArgumentException("Duplicate constant keys in map");
9685
if (valsConstant)
9786
{
98-
// This 'optimzation' works, mostly, unless you have nested map values.
99-
// The nested map values do not participate in the constants map, so you end up with the code to create the keys.
100-
// Result: huge duplication of keyword creation. 3X increase in init time to the REPL.
101-
//IPersistentMap m = PersistentArrayMap.EMPTY;
102-
//for (int i = 0; i < keyvals.length(); i += 2)
103-
// m = m.assoc(((LiteralExpr)keyvals.nth(i)).Val, ((LiteralExpr)keyvals.nth(i + 1)).Val);
104-
//return new ConstantExpr(m);
105-
return ret;
87+
IPersistentMap m = PersistentArrayMap.EMPTY;
88+
for (int i = 0; i < keyvals.length(); i += 2)
89+
m = m.assoc(((LiteralExpr)keyvals.nth(i)).Val, ((LiteralExpr)keyvals.nth(i + 1)).Val);
90+
return new ConstantExpr(m);
10691
}
10792
else
10893
return ret;

0 commit comments

Comments
 (0)