From 09c84ecaffc003a8066de15a4e053dd2e92cdfbd Mon Sep 17 00:00:00 2001 From: Vincent Koc Date: Fri, 4 Dec 2026 13:06:36 +0800 Subject: [PATCH] refactor(pe): share bounded resource count row construction (#16591) --- src/domain/analysisView/peResourcesView.ts | 34 ++++++++++------------ 1 file changed, 15 insertions(+), 19 deletions(-) diff --git a/src/domain/analysisView/peResourcesView.ts b/src/domain/analysisView/peResourcesView.ts index cccb100e0ea..fd41ab7f31d 100644 --- a/src/domain/analysisView/peResourcesView.ts +++ b/src/domain/analysisView/peResourcesView.ts @@ -83,11 +83,12 @@ const summaryIdentity = (identity: PeResourceIdentity): Identity => }; /** Count resources per identity; names are keyed by their exact UTF-16 bytes. */ -const countBy = ( +const countBy = ( resources: PeResources["resources"], key: "type" | "language", -): readonly (readonly [Identity, number])[] => { - const counts = new Map(); + toRow: (identity: Identity) => Row, +) => { + const counts = new Map(); for (const resource of resources) { const identity = resource[key]; const id = @@ -95,10 +96,10 @@ const countBy = ( ? `id:${String(identity.id)}` : `name:${identity.utf16le_hex}`; const entry = counts.get(id); - if (entry === undefined) counts.set(id, [summaryIdentity(identity), 1]); - else entry[1] += 1; + if (entry === undefined) counts.set(id, toRow(summaryIdentity(identity))); + else entry.resource_count += 1; } - return [...counts.values()]; + return byteBoundedList([...counts.values()], COUNT_LIST_BYTES); }; /** Summarize retained PE resource facts without reopening the image. */ @@ -123,19 +124,14 @@ export const projectPeResourcesView = ( directory_count: report.directories.length, resource_count: report.resources.length, icon_group_count: report.icon_groups.length, - types: byteBoundedList( - countBy(report.resources, "type").map(([type, resource_count]) => ({ - type, - resource_count, - })), - COUNT_LIST_BYTES, - ), - languages: byteBoundedList( - countBy(report.resources, "language").map( - ([language, resource_count]) => ({ language, resource_count }), - ), - COUNT_LIST_BYTES, - ), + types: countBy(report.resources, "type", (type) => ({ + type, + resource_count: 1, + })), + languages: countBy(report.resources, "language", (language) => ({ + language, + resource_count: 1, + })), limitation_count: report.limitations.length, }; return ok({