Skip to content

Commit

Permalink
Speed up StyleContextStack.autopush() by skipping slower creation of …
Browse files Browse the repository at this point in the history
…styleOverrideObject and just using the item itself.
  • Loading branch information
estanglerbm committed Jun 16, 2024
1 parent c89ec07 commit 38169bd
Showing 1 changed file with 3 additions and 44 deletions.
47 changes: 3 additions & 44 deletions src/styleContextStack.js
Original file line number Diff line number Diff line change
Expand Up @@ -84,50 +84,9 @@ StyleContextStack.prototype.autopush = function (item) {
this.push(styleNames[i]);
}

var styleProperties = [
'font',
'fontSize',
'fontFeatures',
'bold',
'italics',
'alignment',
'color',
'columnGap',
'fillColor',
'fillOpacity',
'decoration',
'decorationStyle',
'decorationColor',
'background',
'lineHeight',
'characterSpacing',
'noWrap',
'markerColor',
'leadingIndent',
'sup',
'sub'
//'tableCellPadding'
// 'cellBorder',
// 'headerCellBorder',
// 'oddRowCellBorder',
// 'evenRowCellBorder',
// 'tableBorder'
];
var styleOverrideObject = {};
var pushStyleOverrideObject = false;

styleProperties.forEach(function (key) {
if (!isUndefined(item[key]) && !isNull(item[key])) {
styleOverrideObject[key] = item[key];
pushStyleOverrideObject = true;
}
});

if (pushStyleOverrideObject) {
this.push(styleOverrideObject);
}

return styleNames.length + (pushStyleOverrideObject ? 1 : 0);
// rather than spend significant time making a styleOverrideObject, just add item
this.push(item);
return styleNames.length + 1;
};

/**
Expand Down

0 comments on commit 38169bd

Please sign in to comment.