Skip to content

Commit

Permalink
Cache size of all lines except the last
Browse files Browse the repository at this point in the history
  • Loading branch information
sunesimonsen committed Sep 11, 2015
1 parent 215a1c1 commit 09f6d44
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion lib/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,10 @@ var utils = {
},

calculateLineSize: function (line) {
if (line.size) {
return line.size;
}

var size = { height: 1, width: 0 };
line.forEach(function (outputEntry) {
var outputEntrySize = utils.calculateOutputEntrySize(outputEntry);
Expand All @@ -46,10 +50,13 @@ var utils = {

calculateSize: function (lines) {
var size = { height: 0, width: 0 };
lines.forEach(function (line) {
lines.forEach(function (line, index) {
var lineSize = utils.calculateLineSize(line);
size.height += lineSize.height;
size.width = Math.max(size.width, lineSize.width);
if (index < lines.length - 1) {
line.size = lineSize;
}
});
return size;
},
Expand Down

0 comments on commit 09f6d44

Please sign in to comment.