Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add local eslint rule rule for banning concat and new performance test #690

Draft
wants to merge 3 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 24 additions & 0 deletions eslint-local-rules.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,30 @@
'use strict';

module.exports = {
'ban-concat': {
meta: {
type: 'suggestion',
schema: [],
},
create(context) {
return {
CallExpression(node) {
if (
(
node.callee.property &&
node.callee.property.name === 'concat' &&
node.callee?.object?.name !== 'Buffer'
) || (
node.callee?.object?.property?.name === 'concat' &&
node.callee?.object?.object?.type === 'ArrayExpression'
)
) {
context.report({node, message: 'Use obj.push(...data) instead of obj = obj.concat(data)'})
}
},
}
},
},
'ban-foreach': {
meta: {
type: 'suggestion',
Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@
"error",
"always"
],
"local-rules/ban-concat": 2,
"local-rules/ban-foreach": 2,
"local-rules/import-extensions": 2
}
Expand Down
3 changes: 1 addition & 2 deletions src/bidi.js
Original file line number Diff line number Diff line change
Expand Up @@ -101,8 +101,7 @@ Bidi.prototype.registerFeatures = function (script, tags) {
if (!Object.prototype.hasOwnProperty.call(this.featuresTags, script)) {
this.featuresTags[script] = supportedTags;
} else {
this.featuresTags[script] =
this.featuresTags[script].concat(supportedTags);
this.featuresTags[script].push(...supportedTags);
}
};

Expand Down
3 changes: 2 additions & 1 deletion src/features/arab/arabicPresentationForms.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@ import applySubstitution from '../applySubstitution.js';
* @param {ContextParams} charContextParams context params of a char
*/
function willConnectPrev(charContextParams) {
let backtrack = [].concat(charContextParams.backtrack);
let backtrack = [...charContextParams.backtrack];

for (let i = backtrack.length - 1; i >= 0; i--) {
const prevChar = backtrack[i];
const isolated = isIsolatedArabicChar(prevChar);
Expand Down
4 changes: 2 additions & 2 deletions src/features/featureQuery.js
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ function chainingSubstitutionFormat3(contextParams, subtable) {
subtable.lookaheadCoverage, lookaheadParams
);
// BACKTRACK LOOKUP //
let backtrackContext = [].concat(contextParams.backtrack);
let backtrackContext = [...contextParams.backtrack];
backtrackContext.reverse();
while (backtrackContext.length && isTashkeelArabicChar(backtrackContext[0].char)) {
backtrackContext.shift();
Expand Down Expand Up @@ -375,7 +375,7 @@ FeatureQuery.prototype.lookupFeature = function (query) {
`for script '${query.script}'.`
);
const lookups = this.getFeatureLookups(feature);
const substitutions = [].concat(contextParams.context);
const substitutions = [...contextParams.context];
for (let l = 0; l < lookups.length; l++) {
const lookupTable = lookups[l];
const subtables = this.getLookupSubtables(lookupTable);
Expand Down
3 changes: 1 addition & 2 deletions src/path.js
Original file line number Diff line number Diff line change
Expand Up @@ -76,8 +76,7 @@ function optimizeCommands(commands) {
}
}
}
commands = [].concat.apply([], subpaths); // flatten again
return commands;
return [...subpaths.flat()]; // flatten again
}

/**
Expand Down
14 changes: 9 additions & 5 deletions src/substitution.js
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ Substitution.prototype.getLigatures = function(feature, script, language) {
for (let k = 0; k < ligSet.length; k++) {
const lig = ligSet[k];
ligatures.push({
sub: [startGlyph].concat(lig.components),
sub: [startGlyph, ...lig.components],
by: lig.ligGlyph
});
}
Expand Down Expand Up @@ -309,15 +309,19 @@ Substitution.prototype.getFeature = function(feature, script, language) {
switch (feature) {
case 'aalt':
case 'salt':
return this.getSingle(feature, script, language)
.concat(this.getAlternates(feature, script, language));
return [
...this.getSingle(feature, script, language),
...this.getAlternates(feature, script, language)
];
case 'dlig':
case 'liga':
case 'rlig':
return this.getLigatures(feature, script, language);
case 'ccmp':
return this.getMultiple(feature, script, language)
.concat(this.getLigatures(feature, script, language));
return [
...this.getMultiple(feature, script, language),
...this.getLigatures(feature, script, language)
];
case 'stch':
return this.getMultiple(feature, script, language);
}
Expand Down
98 changes: 49 additions & 49 deletions src/table.js
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ function recordList(itemName, records, itemCallback) {
let fields = [];
fields[0] = {name: itemName + 'Count', type: 'USHORT', value: count};
for (let i = 0; i < count; i++) {
fields = fields.concat(itemCallback(records[i], i));
fields.push(...itemCallback(records[i], i));
}
return fields;
}
Expand All @@ -101,21 +101,19 @@ function recordList(itemName, records, itemCallback) {
*/
function Coverage(coverageTable) {
if (coverageTable.format === 1) {
Table.call(this, 'coverageTable',
[{name: 'coverageFormat', type: 'USHORT', value: 1}]
.concat(ushortList('glyph', coverageTable.glyphs))
);
Table.call(this, 'coverageTable', [
{name: 'coverageFormat', type: 'USHORT', value: 1},
...ushortList('glyph', coverageTable.glyphs)
]);
} else if (coverageTable.format === 2) {
Table.call(this, 'coverageTable',
[{name: 'coverageFormat', type: 'USHORT', value: 2}]
.concat(recordList('rangeRecord', coverageTable.ranges, function(RangeRecord, i) {
return [
{name: 'startGlyphID' + i, type: 'USHORT', value: RangeRecord.start},
{name: 'endGlyphID' + i, type: 'USHORT', value: RangeRecord.end},
{name: 'startCoverageIndex' + i, type: 'USHORT', value: RangeRecord.index},
];
}))
);
Table.call(this, 'coverageTable', [
{name: 'coverageFormat', type: 'USHORT', value: 2},
...recordList('rangeRecord', coverageTable.ranges, (RangeRecord, i) => [
{name: 'startGlyphID' + i, type: 'USHORT', value: RangeRecord.start},
{name: 'endGlyphID' + i, type: 'USHORT', value: RangeRecord.end},
{name: 'startCoverageIndex' + i, type: 'USHORT', value: RangeRecord.index},
])
]);
} else {
check.assert(false, 'Coverage format must be 1 or 2.');
}
Expand All @@ -134,19 +132,22 @@ function ScriptList(scriptListTable) {
{name: 'script' + i, type: 'TABLE', value: new Table('scriptTable', [
{name: 'defaultLangSys', type: 'TABLE', value: new Table('defaultLangSys', [
{name: 'lookupOrder', type: 'USHORT', value: 0},
{name: 'reqFeatureIndex', type: 'USHORT', value: defaultLangSys.reqFeatureIndex}]
.concat(ushortList('featureIndex', defaultLangSys.featureIndexes)))}
].concat(recordList('langSys', script.langSysRecords, function(langSysRecord, i) {
const langSys = langSysRecord.langSys;
return [
{name: 'langSysTag' + i, type: 'TAG', value: langSysRecord.tag},
{name: 'langSys' + i, type: 'TABLE', value: new Table('langSys', [
{name: 'lookupOrder', type: 'USHORT', value: 0},
{name: 'reqFeatureIndex', type: 'USHORT', value: langSys.reqFeatureIndex}
].concat(ushortList('featureIndex', langSys.featureIndexes)))}
];
})))}
];
{name: 'reqFeatureIndex', type: 'USHORT', value: defaultLangSys.reqFeatureIndex},
...ushortList('featureIndex', defaultLangSys.featureIndexes)
])},
...recordList('langSys', script.langSysRecords, (langSysRecord, i) => {
const langSys = langSysRecord.langSys;
return [
{name: 'langSysTag' + i, type: 'TAG', value: langSysRecord.tag},
{name: 'langSys' + i, type: 'TABLE', value: new Table('langSys', [
{name: 'lookupOrder', type: 'USHORT', value: 0},
{name: 'reqFeatureIndex', type: 'USHORT', value: langSys.reqFeatureIndex},
...ushortList('featureIndex', langSys.featureIndexes)
])}
];
})
])}
];
})
);
}
Expand All @@ -168,8 +169,9 @@ function FeatureList(featureListTable) {
{name: 'featureTag' + i, type: 'TAG', value: featureRecord.tag},
{name: 'feature' + i, type: 'TABLE', value: new Table('featureTable', [
{name: 'featureParams', type: 'USHORT', value: feature.featureParams},
].concat(ushortList('lookupListIndex', feature.lookupListIndexes)))}
];
...ushortList('lookupListIndex', feature.lookupListIndexes)
])}
];
})
);
}
Expand All @@ -190,8 +192,9 @@ function LookupList(lookupListTable, subtableMakers) {
check.assert(!!subtableCallback, 'Unable to write GSUB lookup type ' + lookupTable.lookupType + ' tables.');
return new Table('lookupTable', [
{name: 'lookupType', type: 'USHORT', value: lookupTable.lookupType},
{name: 'lookupFlag', type: 'USHORT', value: lookupTable.lookupFlag}
].concat(tableList('subtable', lookupTable.subtables, subtableCallback)));
{name: 'lookupFlag', type: 'USHORT', value: lookupTable.lookupFlag},
...tableList('subtable', lookupTable.subtables, subtableCallback)
]);
}));
}
LookupList.prototype = Object.create(Table.prototype);
Expand All @@ -209,24 +212,21 @@ LookupList.prototype.constructor = LookupList;
*/
function ClassDef(classDefTable) {
if (classDefTable.format === 1) {
Table.call(this, 'classDefTable',
[
{name: 'classFormat', type: 'USHORT', value: 1},
{name: 'startGlyphID', type: 'USHORT', value: classDefTable.startGlyph}
]
.concat(ushortList('glyph', classDefTable.classes))
);
Table.call(this, 'classDefTable', [
{name: 'classFormat', type: 'USHORT', value: 1},
{name: 'startGlyphID', type: 'USHORT', value: classDefTable.startGlyph},
...ushortList('glyph', classDefTable.classes)
]);
} else if (classDefTable.format === 2) {
Table.call(this, 'classDefTable',
[{name: 'classFormat', type: 'USHORT', value: 2}]
.concat(recordList('rangeRecord', classDefTable.ranges, function(RangeRecord, i) {
return [
{name: 'startGlyphID' + i, type: 'USHORT', value: RangeRecord.start},
{name: 'endGlyphID' + i, type: 'USHORT', value: RangeRecord.end},
{name: 'class' + i, type: 'USHORT', value: RangeRecord.classId},
];
}))
);
Table.call(this, 'classDefTable', [
{name: 'classFormat', type: 'USHORT', value: 2},
...recordList('rangeRecord', classDefTable.ranges, (RangeRecord, i) => [
{name: 'startGlyphID' + i, type: 'USHORT', value: RangeRecord.start},
{name: 'endGlyphID' + i, type: 'USHORT', value: RangeRecord.end},
{name: 'class' + i, type: 'USHORT', value: RangeRecord.classId},
])
]);

} else {
check.assert(false, 'Class format must be 1 or 2.');
}
Expand Down
6 changes: 3 additions & 3 deletions src/tables/avar.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,10 @@ function makeAvarSegmentMap(n, axis) {
let axisValueMaps = [];
for (let i = 0; i < axis.axisValueMaps.length; i++) {
const valueMap = makeAvarAxisValueMap(`${n}_${i}`, axis.axisValueMaps[i]);
axisValueMaps = axisValueMaps.concat(valueMap.fields);
axisValueMaps.push(...valueMap.fields);
}

returnTable.fields = returnTable.fields.concat(axisValueMaps);
returnTable.fields.push(...axisValueMaps);

return returnTable;
}
Expand All @@ -40,7 +40,7 @@ function makeAvarTable(avar, fvar) {

for (let i = 0; i < avar.axisSegmentMaps.length; i++) {
const axisRecord = makeAvarSegmentMap(i, avar.axisSegmentMaps[i]);
result.fields = result.fields.concat(axisRecord.fields);
result.fields.push(...axisRecord.fields);
}

return result;
Expand Down
4 changes: 2 additions & 2 deletions src/tables/fvar.js
Original file line number Diff line number Diff line change
Expand Up @@ -99,11 +99,11 @@ function makeFvarTable(fvar, names) {
result.offsetToData = result.sizeOf();

for (let i = 0; i < fvar.axes.length; i++) {
result.fields = result.fields.concat(makeFvarAxis(i, fvar.axes[i], names));
result.fields.push(...makeFvarAxis(i, fvar.axes[i], names));
}

for (let j = 0; j < fvar.instances.length; j++) {
result.fields = result.fields.concat(makeFvarInstance(j, fvar.instances[j], fvar.axes, names));
result.fields.push(...makeFvarInstance(j, fvar.instances[j], fvar.axes, names));
}

return result;
Expand Down
2 changes: 1 addition & 1 deletion src/tables/glyf.js
Original file line number Diff line number Diff line change
Expand Up @@ -290,7 +290,7 @@ function buildPath(glyphs, glyph) {
transform.dy = firstPt.y - secondPt.y;
transformedPoints = transformPoints(componentGlyph.points, transform);
}
glyph.points = glyph.points.concat(transformedPoints);
glyph.points.push(...transformedPoints);
}
}
}
Expand Down
Loading
Loading