Skip to content

Commit e4d3552

Browse files
🚴 perf: Exploit property mangling to reduce bundle size.
1 parent be947d0 commit e4d3552

File tree

16 files changed

+199
-167
lines changed

16 files changed

+199
-167
lines changed

mangle.json

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
{
2+
"minify": {
3+
"mangle": {
4+
"properties": {
5+
"regex": "^_[^_]"
6+
}
7+
}
8+
},
9+
"props": {
10+
"props": {
11+
"$_left": "l",
12+
"$_middle": "m",
13+
"$_right": "r",
14+
"$_tree": "t",
15+
"$_thunk": "f",
16+
"$_node": "n",
17+
"$_digit": "d"
18+
}
19+
}
20+
}

src/0-core/_fast/_digit.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import {One, Two, Three} from '../../1-digit/index.js';
55
* Creates a Digit from as small list.
66
*
77
* It should never be called on length 4 lists since it is only called
8-
* on results of splitDigit which outputs lists of length at most 3.
8+
* on results of _splitDigit which outputs lists of length at most 3.
99
*
1010
* @param {Array} list A list of length 1, 2, or 3.
1111
* @return {Digit} A digit containing the elements of list in order.

src/0-core/split/Split.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
export function Split(left, middle, right) {
2-
this.left = left;
3-
this.middle = middle;
4-
this.right = right;
2+
this._left = left;
3+
this._middle = middle;
4+
this._right = right;
55
}

src/0-core/split/deepL.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ export function deepL(M, left, middle, right) {
1414

1515
return new Deep(
1616
M,
17-
middle.head().digit(),
17+
middle.head()._digit(),
1818
delay(() => middle.tail()),
1919
right,
2020
);

src/0-core/split/deepR.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ export function deepR(M, left, middle, right) {
1616
M,
1717
left,
1818
delay(() => middle.init()),
19-
middle.last().digit(),
19+
middle.last()._digit(),
2020
);
2121
}
2222

src/1-digit/1-One.js

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -39,14 +39,14 @@ One.prototype.cons = function (value) {
3939
return new Two(value, this.a);
4040
};
4141

42-
One.prototype.node = function (_M) {
42+
One.prototype._node = function (_M) {
4343
throw new Error('cannot convert One to node');
4444
};
4545

4646
/**
4747
* It is assumed that p(i+|this|) is true.
4848
*/
49-
One.prototype.splitDigit = function (p, i, M) {
49+
One.prototype._splitDigit = function (p, i, M) {
5050
assert(p(M.plus(i, this.measure(M)))); // /!\ Potential Heisenbug generator.
5151
return new Split([], this.a, []);
5252
};
@@ -104,17 +104,17 @@ One.prototype._nodes_with_list_and_two = function (M, list, other) {
104104
// eslint-disable-next-line default-case
105105
switch (list.length) {
106106
case 1:
107-
return [other.node(M), node2(M, list[0], this.a)];
107+
return [other._node(M), node2(M, list[0], this.a)];
108108
case 2:
109-
return [other.node(M), node3(M, list[0], list[1], this.a)];
109+
return [other._node(M), node3(M, list[0], list[1], this.a)];
110110
case 3:
111111
return [
112112
node3(M, other.a, other.b, list[0]),
113113
node3(M, list[1], list[2], this.a),
114114
];
115115
case 4:
116116
return [
117-
other.node(M),
117+
other._node(M),
118118
node3(M, list[0], list[1], list[2]),
119119
node2(M, list[3], this.a),
120120
];
@@ -127,18 +127,18 @@ One.prototype._nodes_with_list_and_three = function (M, list, other) {
127127
// eslint-disable-next-line default-case
128128
switch (list.length) {
129129
case 1:
130-
return [other.node(M), node2(M, list[0], this.a)];
130+
return [other._node(M), node2(M, list[0], this.a)];
131131
case 2:
132-
return [other.node(M), node3(M, list[0], list[1], this.a)];
132+
return [other._node(M), node3(M, list[0], list[1], this.a)];
133133
case 3:
134134
return [
135-
other.node(M),
135+
other._node(M),
136136
node2(M, list[0], list[1]),
137137
node2(M, list[2], this.a),
138138
];
139139
case 4:
140140
return [
141-
other.node(M),
141+
other._node(M),
142142
node2(M, list[0], list[1]),
143143
node3(M, list[2], list[3], this.a),
144144
];

src/1-digit/2-Two.js

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -40,14 +40,14 @@ Two.prototype.cons = function (value) {
4040
return new Three(value, this.a, this.b);
4141
};
4242

43-
Two.prototype.node = function (M) {
43+
Two.prototype._node = function (M) {
4444
return new Node2(this.measure(M), this.a, this.b);
4545
};
4646

4747
/**
4848
* It is assumed that p(i+|this|) is true.
4949
*/
50-
Two.prototype.splitDigit = function (p, i, M) {
50+
Two.prototype._splitDigit = function (p, i, M) {
5151
assert(p(M.plus(i, this.measure(M)))); // /!\ Potential Heisenbug generator.
5252
i = M.plus(i, M.measure(this.a));
5353
if (p(i)) return new Split([], this.a, [this.b]);
@@ -91,20 +91,20 @@ Two.prototype._nodes_with_list_and_one = function (M, list, other) {
9191
// eslint-disable-next-line default-case
9292
switch (list.length) {
9393
case 1:
94-
return [node2(M, other.a, list[0]), this.node(M)];
94+
return [node2(M, other.a, list[0]), this._node(M)];
9595
case 2:
96-
return [node3(M, other.a, list[0], list[1]), this.node(M)];
96+
return [node3(M, other.a, list[0], list[1]), this._node(M)];
9797
case 3:
9898
return [
9999
node2(M, other.a, list[0]),
100100
node2(M, list[1], list[2]),
101-
this.node(M),
101+
this._node(M),
102102
];
103103
case 4:
104104
return [
105105
node2(M, other.a, list[0]),
106106
node3(M, list[1], list[2], list[3]),
107-
this.node(M),
107+
this._node(M),
108108
];
109109
}
110110
};
@@ -117,7 +117,7 @@ Two.prototype._nodes_with_list_and_two = function (M, list, other) {
117117
case 1:
118118
return [node3(M, other.a, other.b, list[0]), node2(M, this.a, this.b)];
119119
case 2:
120-
return [other.node(M), node2(M, list[0], list[1]), this.node(M)];
120+
return [other._node(M), node2(M, list[0], list[1]), this._node(M)];
121121
case 3:
122122
return [
123123
node2(M, other.a, other.b),

src/1-digit/3-Three.js

Lines changed: 34 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -45,14 +45,14 @@ Three.prototype.cons = function (value) {
4545
return new Four(value, this.a, this.b, this.c);
4646
};
4747

48-
Three.prototype.node = function (M) {
48+
Three.prototype._node = function (M) {
4949
return new Node3(this.measure(M), this.a, this.b, this.c);
5050
};
5151

5252
/**
5353
* It is assumed that p(i+|this|) is true.
5454
*/
55-
Three.prototype.splitDigit = function (p, i, M) {
55+
Three.prototype._splitDigit = function (p, i, M) {
5656
assert(p(M.plus(i, this.measure(M)))); // /!\ Potential Heisenbug generator.
5757
i = M.plus(i, M.measure(this.a));
5858
if (p(i)) return new Split([], this.a, [this.b, this.c]);
@@ -72,17 +72,21 @@ Three.prototype._nodes_with_one = function (M, other) {
7272

7373
Three.prototype._nodes_with_two = function (M, other) {
7474
assert(other instanceof Two);
75-
return [other.node(M), this.node(M)];
75+
return [other._node(M), this._node(M)];
7676
};
7777

7878
Three.prototype._nodes_with_three = function (M, other) {
7979
assert(other instanceof Three);
80-
return [other.node(M), this.node(M)];
80+
return [other._node(M), this._node(M)];
8181
};
8282

8383
Three.prototype._nodes_with_four = function (M, other) {
8484
assert(other instanceof Four);
85-
return [node2(M, other.a, other.b), node2(M, other.c, other.d), this.node(M)];
85+
return [
86+
node2(M, other.a, other.b),
87+
node2(M, other.c, other.d),
88+
this._node(M),
89+
];
8690
};
8791

8892
Three.prototype._nodes_with_list = function (M, list, other) {
@@ -95,20 +99,20 @@ Three.prototype._nodes_with_list_and_one = function (M, list, other) {
9599
// eslint-disable-next-line default-case
96100
switch (list.length) {
97101
case 1:
98-
return [node2(M, other.a, list[0]), this.node(M)];
102+
return [node2(M, other.a, list[0]), this._node(M)];
99103
case 2:
100-
return [node3(M, other.a, list[0], list[1]), this.node(M)];
104+
return [node3(M, other.a, list[0], list[1]), this._node(M)];
101105
case 3:
102106
return [
103107
node2(M, other.a, list[0]),
104108
node2(M, list[1], list[2]),
105-
this.node(M),
109+
this._node(M),
106110
];
107111
case 4:
108112
return [
109113
node3(M, other.a, list[0], list[1]),
110114
node2(M, list[2], list[3]),
111-
this.node(M),
115+
this._node(M),
112116
];
113117
}
114118
};
@@ -119,16 +123,20 @@ Three.prototype._nodes_with_list_and_two = function (M, list, other) {
119123
// eslint-disable-next-line default-case
120124
switch (list.length) {
121125
case 1:
122-
return [node3(M, other.a, other.b, list[0]), this.node(M)];
126+
return [node3(M, other.a, other.b, list[0]), this._node(M)];
123127
case 2:
124-
return [other.node(M), node2(M, list[0], list[1]), this.node(M)];
128+
return [other._node(M), node2(M, list[0], list[1]), this._node(M)];
125129
case 3:
126-
return [other.node(M), node3(M, list[0], list[1], list[2]), this.node(M)];
130+
return [
131+
other._node(M),
132+
node3(M, list[0], list[1], list[2]),
133+
this._node(M),
134+
];
127135
case 4:
128136
return [
129137
node3(M, other.a, other.b, list[0]),
130138
node3(M, list[1], list[2], list[3]),
131-
this.node(M),
139+
this._node(M),
132140
];
133141
}
134142
};
@@ -142,18 +150,22 @@ Three.prototype._nodes_with_list_and_three = function (M, list, other) {
142150
return [
143151
node2(M, other.a, other.b),
144152
node2(M, other.c, list[0]),
145-
this.node(M),
153+
this._node(M),
146154
];
147155
case 2:
148-
return [other.node(M), node2(M, list[0], list[1]), this.node(M)];
156+
return [other._node(M), node2(M, list[0], list[1]), this._node(M)];
149157
case 3:
150-
return [other.node(M), node3(M, list[0], list[1], list[2]), this.node(M)];
158+
return [
159+
other._node(M),
160+
node3(M, list[0], list[1], list[2]),
161+
this._node(M),
162+
];
151163
case 4:
152164
return [
153-
other.node(M),
165+
other._node(M),
154166
node2(M, list[0], list[1]),
155167
node2(M, list[2], list[3]),
156-
this.node(M),
168+
this._node(M),
157169
];
158170
}
159171
};
@@ -167,27 +179,27 @@ Three.prototype._nodes_with_list_and_four = function (M, list, other) {
167179
return [
168180
node2(M, other.a, other.b),
169181
node3(M, other.c, other.d, list[0]),
170-
this.node(M),
182+
this._node(M),
171183
];
172184
case 2:
173185
return [
174186
node3(M, other.a, other.b, other.c),
175187
node3(M, other.d, list[0], list[1]),
176-
this.node(M),
188+
this._node(M),
177189
];
178190
case 3:
179191
return [
180192
node2(M, other.a, other.b),
181193
node2(M, other.c, other.d),
182194
node3(M, list[0], list[1], list[2]),
183-
this.node(M),
195+
this._node(M),
184196
];
185197
case 4:
186198
return [
187199
node3(M, other.a, other.b, other.c),
188200
node2(M, other.d, list[0]),
189201
node3(M, list[1], list[2], list[3]),
190-
this.node(M),
202+
this._node(M),
191203
];
192204
}
193205
};

src/1-digit/4-Four.js

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -46,14 +46,14 @@ Four.prototype.cons = function (_value) {
4646
throw new Error('cannot cons digit Four');
4747
};
4848

49-
Four.prototype.node = function (_M) {
49+
Four.prototype._node = function (_M) {
5050
throw new Error('cannot convert Four to node');
5151
};
5252

5353
/**
5454
* It is assumed that p(i+|this|) is true.
5555
*/
56-
Four.prototype.splitDigit = function (p, i, M) {
56+
Four.prototype._splitDigit = function (p, i, M) {
5757
assert(p(M.plus(i, this.measure(M)))); // /!\ Potential Heisenbug generator.
5858
i = M.plus(i, M.measure(this.a));
5959
if (p(i)) return new Split([], this.a, [this.b, this.c, this.d]);
@@ -138,13 +138,13 @@ Four.prototype._nodes_with_list_and_two = function (M, list, other) {
138138
switch (list.length) {
139139
case 1:
140140
return [
141-
other.node(M),
141+
other._node(M),
142142
node3(M, list[0], this.a, this.b),
143143
node2(M, this.c, this.d),
144144
];
145145
case 2:
146146
return [
147-
other.node(M),
147+
other._node(M),
148148
node3(M, list[0], list[1], this.a),
149149
node3(M, this.b, this.c, this.d),
150150
];
@@ -156,7 +156,7 @@ Four.prototype._nodes_with_list_and_two = function (M, list, other) {
156156
];
157157
case 4:
158158
return [
159-
other.node(M),
159+
other._node(M),
160160
node3(M, list[0], list[1], list[2]),
161161
node3(M, list[3], this.a, this.b),
162162
node2(M, this.c, this.d),
@@ -171,26 +171,26 @@ Four.prototype._nodes_with_list_and_three = function (M, list, other) {
171171
switch (list.length) {
172172
case 1:
173173
return [
174-
other.node(M),
174+
other._node(M),
175175
node2(M, list[0], this.a),
176176
node3(M, this.b, this.c, this.d),
177177
];
178178
case 2:
179179
return [
180-
other.node(M),
180+
other._node(M),
181181
node3(M, list[0], list[1], this.a),
182182
node3(M, this.b, this.c, this.d),
183183
];
184184
case 3:
185185
return [
186-
other.node(M),
186+
other._node(M),
187187
node2(M, list[0], list[1]),
188188
node2(M, list[2], this.a),
189189
node3(M, this.b, this.c, this.d),
190190
];
191191
case 4:
192192
return [
193-
other.node(M),
193+
other._node(M),
194194
node2(M, list[0], list[1]),
195195
node3(M, list[2], list[3], this.a),
196196
node3(M, this.b, this.c, this.d),

0 commit comments

Comments
 (0)