Skip to content

Commit

Permalink
perf: remove node cloning to improve performance
Browse files Browse the repository at this point in the history
  • Loading branch information
azat-io committed Aug 5, 2024
1 parent 4130bc2 commit 00b2cc3
Show file tree
Hide file tree
Showing 19 changed files with 20 additions and 20 deletions.
2 changes: 1 addition & 1 deletion rules/sort-array-includes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -115,8 +115,8 @@ export default createEslintRule<Options, MESSAGE_ID>({
? `${element.value}`
: sourceCode.text.slice(...element.range),
size: rangeToDiff(element.range),
node: structuredClone(element),
type: element.type,
node: element,
group,
})
}
Expand Down
2 changes: 1 addition & 1 deletion rules/sort-astro-attributes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -169,8 +169,8 @@ export default createEslintRule<Options<string[]>, MESSAGE_ID>({
}

accumulator.at(-1)!.push({
node: structuredClone(attribute) as TSESTree.Node,
size: rangeToDiff(attribute.range),
node: attribute as TSESTree.Node,
group: getGroup(),
name,
})
Expand Down
2 changes: 1 addition & 1 deletion rules/sort-classes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -387,8 +387,8 @@ export default createEslintRule<Options, MESSAGE_ID>({

let value = {
size: rangeToDiff(member.range),
node: structuredClone(member),
group: getGroup(),
node: member,
dependencies,
name,
}
Expand Down
2 changes: 1 addition & 1 deletion rules/sort-enums.ts
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ export default createEslintRule<Options, MESSAGE_ID>({

let sortingNode = {
size: rangeToDiff(member.range),
node: structuredClone(member),
node: member,
name,
}
accumulator.at(-1)!.push(sortingNode)
Expand Down
2 changes: 1 addition & 1 deletion rules/sort-exports.ts
Original file line number Diff line number Diff line change
Expand Up @@ -81,8 +81,8 @@ export default createEslintRule<Options, MESSAGE_ID>({
) => {
parts.at(-1)!.push({
size: rangeToDiff(node.range),
node: structuredClone(node),
name: node.source.value,
node,
})
}

Expand Down
2 changes: 1 addition & 1 deletion rules/sort-imports.ts
Original file line number Diff line number Diff line change
Expand Up @@ -437,8 +437,8 @@ export default createEslintRule<Options<string[]>, MESSAGE_ID>({

nodes.push({
size: rangeToDiff(node.range),
node: structuredClone(node),
group: computeGroup(node),
node,
name,
...(options.type === 'line-length' &&
options.maxLineLength && {
Expand Down
2 changes: 1 addition & 1 deletion rules/sort-interfaces.ts
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,7 @@ export default createEslintRule<Options<string[]>, MESSAGE_ID>({

let elementSortingNode = {
size: rangeToDiff(element.range),
node: structuredClone(element),
node: element,
name,
}

Expand Down
2 changes: 1 addition & 1 deletion rules/sort-intersection-types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -177,8 +177,8 @@ export default createEslintRule<Options, MESSAGE_ID>({
return {
name: sourceCode.text.slice(...type.range),
size: rangeToDiff(type.range),
node: structuredClone(type),
group: getGroup(),
node: type,
}
})

Expand Down
2 changes: 1 addition & 1 deletion rules/sort-jsx-props.ts
Original file line number Diff line number Diff line change
Expand Up @@ -178,8 +178,8 @@ export default createEslintRule<Options<string[]>, MESSAGE_ID>({

let jsxNode = {
size: rangeToDiff(attribute.range),
node: structuredClone(attribute),
group: getGroup(),
node: attribute,
name,
}

Expand Down
2 changes: 1 addition & 1 deletion rules/sort-maps.ts
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ export default createEslintRule<Options, MESSAGE_ID>({

return {
size: rangeToDiff(element.range),
node: structuredClone(element),
node: element,
name,
}
})
Expand Down
2 changes: 1 addition & 1 deletion rules/sort-named-exports.ts
Original file line number Diff line number Diff line change
Expand Up @@ -93,8 +93,8 @@ export default createEslintRule<Options, MESSAGE_ID>({
}
return {
size: rangeToDiff(specifier.range),
node: structuredClone(specifier),
name: specifier.local.name,
node: specifier,
group,
}
})
Expand Down
2 changes: 1 addition & 1 deletion rules/sort-named-imports.ts
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ export default createEslintRule<Options, MESSAGE_ID>({

return {
size: rangeToDiff(specifier.range),
node: structuredClone(specifier),
node: specifier,
group,
name,
}
Expand Down
2 changes: 1 addition & 1 deletion rules/sort-object-types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,7 @@ export default createEslintRule<Options<string[]>, MESSAGE_ID>({

let memberSortingNode = {
size: rangeToDiff(member.range) - endSize,
node: structuredClone(member),
node: member,
name,
}

Expand Down
2 changes: 1 addition & 1 deletion rules/sort-objects.ts
Original file line number Diff line number Diff line change
Expand Up @@ -298,7 +298,7 @@ export default createEslintRule<Options, MESSAGE_ID>({

let propSortingNode = {
size: rangeToDiff(prop.range),
node: structuredClone(prop),
node: prop,
name,
}

Expand Down
2 changes: 1 addition & 1 deletion rules/sort-svelte-attributes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@ export default createEslintRule<Options<string[]>, MESSAGE_ID>({
}

accumulator.at(-1)!.push({
node: structuredClone(attribute) as unknown as TSESTree.Node,
node: attribute as unknown as TSESTree.Node,
size: rangeToDiff(attribute.range),
group: getGroup(),
name,
Expand Down
4 changes: 2 additions & 2 deletions rules/sort-switch-case.ts
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ export default createEslintRule<Options, MESSAGE_ID>({

return {
size: rangeToDiff(caseNode.test?.range ?? caseNode.range),
node: structuredClone(caseNode),
node: caseNode,
name,
}
},
Expand Down Expand Up @@ -160,7 +160,7 @@ export default createEslintRule<Options, MESSAGE_ID>({
node: right.node,
fix: fixer => {
let additionalFixes: TSESLint.RuleFix[] = []
let nodeGroups = structuredClone(nodes).reduce<
let nodeGroups = nodes.reduce<
SortingNode<TSESTree.SwitchCase>[][]
>(
(
Expand Down
2 changes: 1 addition & 1 deletion rules/sort-union-types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -177,8 +177,8 @@ export default createEslintRule<Options, MESSAGE_ID>({
return {
name: sourceCode.text.slice(...type.range),
size: rangeToDiff(type.range),
node: structuredClone(type),
group: getGroup(),
node: type,
}
})

Expand Down
2 changes: 1 addition & 1 deletion rules/sort-variable-declarations.ts
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ export default createEslintRule<Options, MESSAGE_ID>({

return {
size: rangeToDiff(declaration.range),
node: structuredClone(declaration),
node: declaration,
dependencies,
name,
}
Expand Down
2 changes: 1 addition & 1 deletion rules/sort-vue-attributes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,7 @@ export default createEslintRule<Options<string[]>, MESSAGE_ID>({
}

accumulator.at(-1)!.push({
node: structuredClone(attribute) as unknown as TSESTree.Node,
node: attribute as unknown as TSESTree.Node,
size: rangeToDiff(attribute.range),
group: getGroup(),
name,
Expand Down

0 comments on commit 00b2cc3

Please sign in to comment.