From 4023632ebe23a8cea6a2db53798231a158dfccc2 Mon Sep 17 00:00:00 2001 From: "google-labs-jules[bot]" <161369871+google-labs-jules[bot]@users.noreply.github.com> Date: Sat, 1 Aug 2026 04:27:02 +0000 Subject: [PATCH] perf: replace manual array insertion with native sorting for top-k Co-authored-by: is0692vs <135803462+is0692vs@users.noreply.github.com> --- src/lib/github.ts | 18 ++++-------------- 1 file changed, 4 insertions(+), 14 deletions(-) diff --git a/src/lib/github.ts b/src/lib/github.ts index d35c21bf..6aee19b2 100644 --- a/src/lib/github.ts +++ b/src/lib/github.ts @@ -427,20 +427,10 @@ function processRepoData(repos: RepoNode[]): RepositoryData { } const totalBytes = Array.from(languageMap.values()).reduce((a, b) => a + b.bytes, 0); - const topLanguages: { name: string; bytes: number; color: string }[] = []; - for (const [name, data] of languageMap.entries()) { - if (topLanguages.length < 10) { - topLanguages.push({ name, ...data }); - topLanguages.sort((a, b) => b.bytes - a.bytes); - } else if (data.bytes > topLanguages[9].bytes) { - let i = 8; - while (i >= 0 && topLanguages[i].bytes < data.bytes) { - topLanguages[i + 1] = topLanguages[i]; - i--; - } - topLanguages[i + 1] = { name, ...data }; - } - } + const topLanguages = Array.from(languageMap.entries()) + .sort((a, b) => b[1].bytes - a[1].bytes) + .slice(0, 10) + .map(([name, data]) => ({ name, ...data })); const languages: LanguageStats[] = topLanguages.map(({ name, bytes, color }) => ({ name,