Skip to content

Commit a31b0fd

Browse files
committed
Cache the outputEntry sizes and the line sizes
1 parent 9952fb3 commit a31b0fd

File tree

1 file changed

+20
-4
lines changed

1 file changed

+20
-4
lines changed

lib/utils.js

+20-4
Original file line numberDiff line numberDiff line change
@@ -10,25 +10,41 @@ var utils = {
1010
},
1111

1212
calculateOutputEntrySize: function (outputEntry) {
13+
if (outputEntry.size) {
14+
return outputEntry.size;
15+
}
16+
17+
var size;
1318
switch (outputEntry.style) {
1419
case 'text':
15-
return { width: String(outputEntry.args.content).length, height: 1 };
20+
size = { width: String(outputEntry.args.content).length, height: 1 };
21+
break;
1622
case 'block':
17-
return utils.calculateSize(outputEntry.args);
23+
size = utils.calculateSize(outputEntry.args);
24+
break;
1825
case 'raw':
1926
var arg = outputEntry.args;
20-
return { width: arg.width, height: arg.height };
21-
default: return { width: 0, height: 0 };
27+
size = { width: arg.width, height: arg.height };
28+
break;
29+
default: size = { width: 0, height: 0 };
2230
}
31+
32+
outputEntry.size = size;
33+
return size;
2334
},
2435

2536
calculateLineSize: function (line) {
37+
if (line.size) {
38+
return line.size;
39+
}
40+
2641
var size = { height: 1, width: 0 };
2742
line.forEach(function (outputEntry) {
2843
var outputEntrySize = utils.calculateOutputEntrySize(outputEntry);
2944
size.width += outputEntrySize.width;
3045
size.height = Math.max(outputEntrySize.height, size.height);
3146
});
47+
line.size = size;
3248
return size;
3349
},
3450

0 commit comments

Comments
 (0)