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

speed up diffKeys() with new Set() API #24

Open
TechQuery opened this issue Jul 12, 2024 · 0 comments
Open

speed up diffKeys() with new Set() API #24

TechQuery opened this issue Jul 12, 2024 · 0 comments
Labels
enhancement Some improvements

Comments

@TechQuery
Copy link
Member

TechQuery commented Jul 12, 2024

Document

  1. https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Set/intersection
  2. https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Set/difference

Target

web-utility/source/data.ts

Lines 121 to 138 in 0530fc2

export function diffKeys<T extends IndexKey>(oldList: T[], newList: T[]) {
const map = {} as Record<T, DiffStatus>;
for (const item of oldList) map[item] = DiffStatus.Old;
for (const item of newList) {
map[item] ||= 0;
map[item] += DiffStatus.New;
}
return {
map,
group: groupBy(
Object.entries<DiffStatus>(map),
([key, status]) => status
)
};
}

@TechQuery TechQuery added the enhancement Some improvements label Jul 12, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement Some improvements
Projects
Status: To do
Development

No branches or pull requests

1 participant