From 5cd86586431698d80facc62259ff04a91310f16a Mon Sep 17 00:00:00 2001 From: Vincent Koc Date: Wed, 25 Nov 2026 23:19:22 +0800 Subject: [PATCH] refactor(domain): reuse ordered map appends in index builders (#14548) --- ...econstructionObligationLedgerEvaluation.ts | 5 ++--- .../environmentIdentifierListSurvivors.ts | 5 ++--- .../ElectronBoundaryGraphCallPaths.ts | 5 ++--- .../javascript/ElectronBoundaryGraphIpc.ts | 5 ++--- .../JavaScriptArtifactGraphDocuments.ts | 5 ++--- .../JavaScriptSemanticGraphBuilder.ts | 6 ++---- src/application/native/NativeUiActionTrace.ts | 5 ++--- src/artifacts/ReleaseExposureReader.ts | 5 ++--- src/artifacts/fit/FitStructure.ts | 5 ++--- .../inventory/ArtifactGraphConstruction.ts | 15 +++++++-------- src/browser/CdpCaptureDomNamespaces.ts | 5 ++--- .../EnvironmentStateExtraction.ts | 5 ++--- .../WebNetworkApiSurfaceAccumulator.ts | 9 +++------ .../analysisView/artifactInventoryView.ts | 9 +++------ src/domain/analysisView/binaryLayoutView.ts | 5 ++--- .../analysisView/environmentManifestRules.ts | 13 ++++--------- .../environmentStateInitialOrder.ts | 5 ++--- .../analysisView/environmentStateListQuery.ts | 5 ++--- .../environmentStateQueryCalls.ts | 5 ++--- .../analysisView/environmentStateRules.ts | 5 ++--- .../analysisView/environmentStateVariants.ts | 9 +++------ .../environmentStateWriteComposed.ts | 5 ++--- .../analysisView/javascriptApplicationView.ts | 13 ++++--------- src/domain/analysisView/managedMemberView.ts | 5 ++--- src/domain/analysisView/pcapCaptureView.ts | 5 ++--- .../analysisView/playwrightTraceView.ts | 5 ++--- src/domain/artifactComparison.ts | 6 ++---- src/domain/artifactInventoryEvidence.ts | 5 ++--- src/domain/desktop/positionalKeys.ts | 5 ++--- src/domain/desktop/viewPointer.ts | 5 ++--- src/domain/functionComparisonDimensions.ts | 9 +++------ .../javascript/electronWrappedCallPaths.ts | 5 ++--- .../javascriptApplicationVersionKeys.ts | 5 ++--- .../javascript/javascriptFeatureTrace.ts | 5 ++--- .../javascriptRuntimeStaticCandidates.ts | 6 ++---- .../javascriptSemanticFingerprints.ts | 5 ++--- .../javascriptSemanticObjectReferences.ts | 5 ++--- src/domain/managed/managedMemberComparison.ts | 10 +++------- .../managedMemberComparisonCoverage.ts | 5 ++--- src/domain/native/nativeInvestigationGraph.ts | 19 +++++-------------- src/domain/reconstructionCoverage.ts | 5 ++--- .../reconstructionCoverageEvaluation.ts | 5 ++--- src/domain/reconstructionVerification.ts | 5 ++--- src/domain/rust/rustBinary.ts | 5 ++--- src/domain/symbolAnalysis.ts | 5 ++--- src/domain/webInventory.ts | 6 ++---- src/dotnet/ManagedFieldConstants.ts | 5 ++--- src/il2cpp/Il2cppBinaryGenerics.ts | 5 ++--- src/resources/ArtifactPaths.ts | 5 ++--- 49 files changed, 115 insertions(+), 195 deletions(-) diff --git a/src/application/ReconstructionObligationLedgerEvaluation.ts b/src/application/ReconstructionObligationLedgerEvaluation.ts index 82134d5943b..ae3062270f7 100644 --- a/src/application/ReconstructionObligationLedgerEvaluation.ts +++ b/src/application/ReconstructionObligationLedgerEvaluation.ts @@ -1,3 +1,4 @@ +import { appendToMapList } from "../domain/appendToMapList.js"; import type { Evidence } from "../domain/evidence.js"; import type { ReconstructionObligationSources } from "./ReconstructionObligationLedgerRequest.js"; import { @@ -44,9 +45,7 @@ const groupByObligation = ( ): ReadonlyMap => { const groups = new Map(); for (const entry of entries) { - const group = groups.get(entry.obligation_id); - if (group === undefined) groups.set(entry.obligation_id, [entry]); - else group.push(entry); + appendToMapList(groups, entry.obligation_id, entry); } return groups; }; diff --git a/src/application/environment/environmentIdentifierListSurvivors.ts b/src/application/environment/environmentIdentifierListSurvivors.ts index b34f7e88028..de56a4ab381 100644 --- a/src/application/environment/environmentIdentifierListSurvivors.ts +++ b/src/application/environment/environmentIdentifierListSurvivors.ts @@ -1,3 +1,4 @@ +import { appendToMapList } from "../../domain/appendToMapList.js"; /** The two keys are different namespaces: literal equality is typed, learned equality is textual. */ export interface IdentifierListIdentity { readonly literal: string | undefined; @@ -217,9 +218,7 @@ const matchingGroups = ( envByIndex.set(index, group); if (group.indices.length === 1) for (const key of identifierListKeys(identity)) { - const candidates = envByKey.get(key); - if (candidates === undefined) envByKey.set(key, [group]); - else candidates.push(group); + appendToMapList(envByKey, key, group); } } for (const live of liveGroups.values()) { diff --git a/src/application/javascript/ElectronBoundaryGraphCallPaths.ts b/src/application/javascript/ElectronBoundaryGraphCallPaths.ts index 4c8e4490c01..9c47f549b00 100644 --- a/src/application/javascript/ElectronBoundaryGraphCallPaths.ts +++ b/src/application/javascript/ElectronBoundaryGraphCallPaths.ts @@ -1,3 +1,4 @@ +import { appendToMapList } from "../../domain/appendToMapList.js"; import { javascriptSourceRangeKey } from "../../domain/javascript/javascriptSourceCoordinates.js"; import type { ApplicationNode } from "../../domain/javascript/javascriptApplicationGraphSchemas.js"; import { IPC_COVERAGE_LIMITED_PAIRING_BASIS } from "../../domain/javascript/javascriptApplicationGraphSchemas.js"; @@ -247,9 +248,7 @@ const indexProjectedPaths = ( byChannel = new Map(); indexed[entryKind].set(entry.file.path, byChannel); } - const bucket = byChannel.get(channel); - if (bucket === undefined) byChannel.set(channel, [entry]); - else bucket.push(entry); + appendToMapList(byChannel, channel, entry); } return indexed; }; diff --git a/src/application/javascript/ElectronBoundaryGraphIpc.ts b/src/application/javascript/ElectronBoundaryGraphIpc.ts index 200f7d1f7f4..21061445204 100644 --- a/src/application/javascript/ElectronBoundaryGraphIpc.ts +++ b/src/application/javascript/ElectronBoundaryGraphIpc.ts @@ -1,3 +1,4 @@ +import { appendToMapList } from "../../domain/appendToMapList.js"; import { compareJavaScriptSourcePoints, javascriptSourceRangeKey, @@ -376,9 +377,7 @@ const addValidationObservations = (state: IpcGraphState): void => { const handlersByPath = new Map(); for (const record of state.records) { if (record.finding.handler_location === null) continue; - const list = handlersByPath.get(record.file.path); - if (list === undefined) handlersByPath.set(record.file.path, [record]); - else list.push(record); + appendToMapList(handlersByPath, record.file.path, record); } for (const analyzed of state.context.analysis.files) { const { file, javascript } = analyzed; diff --git a/src/application/javascript/JavaScriptArtifactGraphDocuments.ts b/src/application/javascript/JavaScriptArtifactGraphDocuments.ts index 6f538f17118..11e8bfdbdec 100644 --- a/src/application/javascript/JavaScriptArtifactGraphDocuments.ts +++ b/src/application/javascript/JavaScriptArtifactGraphDocuments.ts @@ -1,3 +1,4 @@ +import { appendToMapList } from "../../domain/appendToMapList.js"; import { addArtifactContainsEdge, addStaticInferenceEdge, @@ -22,9 +23,7 @@ export const addJavaScriptHtmlRoles = ( for (const script of context.analysis.html_scripts) { if (script.script_type !== "classic" && script.script_type !== "module") continue; - const existing = byHtml.get(script.html_path); - if (existing === undefined) byHtml.set(script.html_path, [script]); - else existing.push(script); + appendToMapList(byHtml, script.html_path, script); } for (const [htmlPath, scripts] of byHtml) { const html = context.filesByPath.get(htmlPath); diff --git a/src/application/javascript/JavaScriptSemanticGraphBuilder.ts b/src/application/javascript/JavaScriptSemanticGraphBuilder.ts index 7292faf2473..9451c5fc2a2 100644 --- a/src/application/javascript/JavaScriptSemanticGraphBuilder.ts +++ b/src/application/javascript/JavaScriptSemanticGraphBuilder.ts @@ -1,3 +1,4 @@ +import { appendToMapList } from "../../domain/appendToMapList.js"; import type { AnalysisParameterLimit } from "../../domain/analysisSettings.js"; import { createJavaScriptSemanticGraph, @@ -1072,10 +1073,7 @@ const projectCalls = (context: FileContext): void => { JavaScriptSemanticCallReturnFlow[] >(); for (const flow of context.ir.callReturnFlows) { - const grouped = returnFlowsByCallSite.get(flow.callSiteId); - if (grouped === undefined) - returnFlowsByCallSite.set(flow.callSiteId, [flow]); - else grouped.push(flow); + appendToMapList(returnFlowsByCallSite, flow.callSiteId, flow); addRelation(context.state, { source: context.returnSiteNodes.get(flow.returnSiteId), target: context.callSiteNodes.get(flow.callSiteId), diff --git a/src/application/native/NativeUiActionTrace.ts b/src/application/native/NativeUiActionTrace.ts index db0a7415fb6..a12934bfbfc 100644 --- a/src/application/native/NativeUiActionTrace.ts +++ b/src/application/native/NativeUiActionTrace.ts @@ -1,3 +1,4 @@ +import { appendToMapList } from "../../domain/appendToMapList.js"; import { analysisErrorWithCleanupDependencies } from "../../domain/analysisErrorCleanup.js"; import { permitsCapabilityFallback } from "../CapabilityFallback.js"; import { stopsTraversal } from "../CallRelationshipTraversal.js"; @@ -635,9 +636,7 @@ const graphNodeDepths = ( !known.has(edge.to) ) continue; - const targets = outgoing.get(edge.from); - if (targets === undefined) outgoing.set(edge.from, [edge.to]); - else targets.push(edge.to); + appendToMapList(outgoing, edge.from, edge.to); } const depths = new Map([[start, 0]]); const queue = [start]; diff --git a/src/artifacts/ReleaseExposureReader.ts b/src/artifacts/ReleaseExposureReader.ts index 859e8da673c..594f757a86e 100644 --- a/src/artifacts/ReleaseExposureReader.ts +++ b/src/artifacts/ReleaseExposureReader.ts @@ -1,3 +1,4 @@ +import { appendToMapList } from "../domain/appendToMapList.js"; import { RELEASE_EXPOSURE_AUDIT_OPERATION as OPERATION, releaseExposureFailure, @@ -2945,9 +2946,7 @@ const listContainer = async ( } listed.push(entry); const key = logicalPathNfc(entry.path).replace(/\/+$/u, ""); - const sameName = byPath.get(key); - if (sameName === undefined) byPath.set(key, [entry]); - else sameName.push(entry); + appendToMapList(byPath, key, entry); } const coverage = traversal.snapshot(); if (coverage.status === "unknown") state.coverageUnknown = true; diff --git a/src/artifacts/fit/FitStructure.ts b/src/artifacts/fit/FitStructure.ts index 2befecfd9f0..93325ab4bab 100644 --- a/src/artifacts/fit/FitStructure.ts +++ b/src/artifacts/fit/FitStructure.ts @@ -1,3 +1,4 @@ +import { appendToMapList } from "../../domain/appendToMapList.js"; import { createHash } from "node:crypto"; import { crc32 } from "node:zlib"; import { @@ -610,9 +611,7 @@ export const readFitStructure = ( const children = new Map(); for (const node of tree.nodes) { if (node.parent === null) continue; - const siblings = children.get(node.parent); - if (siblings === undefined) children.set(node.parent, [node]); - else siblings.push(node); + appendToMapList(children, node.parent, node); } const root = byPath.get("/"); if (root === undefined || !byPath.has("/images")) diff --git a/src/artifacts/inventory/ArtifactGraphConstruction.ts b/src/artifacts/inventory/ArtifactGraphConstruction.ts index af171b5d2de..9fcce875aee 100644 --- a/src/artifacts/inventory/ArtifactGraphConstruction.ts +++ b/src/artifacts/inventory/ArtifactGraphConstruction.ts @@ -1,3 +1,4 @@ +import { appendToMapList } from "../../domain/appendToMapList.js"; import { artifactFormatDescriptor } from "../artifactFormats.js"; import { isStandaloneArtifactFormat, @@ -74,10 +75,7 @@ export const indexDestinationOccurrencesByPath = ( const byPath = new Map(); for (const occurrence of occurrences) { if (!hasDestinationPath(occurrence.entry_kind)) continue; - const matches = byPath.get(occurrence.logical_path); - if (matches === undefined) - byPath.set(occurrence.logical_path, [occurrence]); - else matches.push(occurrence); + appendToMapList(byPath, occurrence.logical_path, occurrence); } return byPath; }; @@ -193,10 +191,11 @@ export const materializeDirectoryNodes = ( const childrenByParent = new Map(); for (const occurrence of occurrences) { if (occurrence.parent_occurrence_id === null) continue; - const children = childrenByParent.get(occurrence.parent_occurrence_id); - if (children === undefined) - childrenByParent.set(occurrence.parent_occurrence_id, [occurrence]); - else children.push(occurrence); + appendToMapList( + childrenByParent, + occurrence.parent_occurrence_id, + occurrence, + ); } for (const directory of directories) { const children = (childrenByParent.get(directory.occurrence_id) ?? []) diff --git a/src/browser/CdpCaptureDomNamespaces.ts b/src/browser/CdpCaptureDomNamespaces.ts index e06c963c635..c7208d19698 100644 --- a/src/browser/CdpCaptureDomNamespaces.ts +++ b/src/browser/CdpCaptureDomNamespaces.ts @@ -1,3 +1,4 @@ +import { appendToMapList } from "../domain/appendToMapList.js"; import type { CdpCommandResult } from "./protocol/CdpCommands.js"; import type { SnapshotDocumentNodes, @@ -152,9 +153,7 @@ const resolveXmlElements = ( if (parent === undefined) continue; if (parent < 0) pending.push({ node }); else { - const siblings = children.get(parent); - if (siblings === undefined) children.set(parent, [node]); - else siblings.push(node); + appendToMapList(children, parent, node); } } const bindings = new Map(); diff --git a/src/domain/analysisView/EnvironmentStateExtraction.ts b/src/domain/analysisView/EnvironmentStateExtraction.ts index 477164471ab..c46969f670a 100644 --- a/src/domain/analysisView/EnvironmentStateExtraction.ts +++ b/src/domain/analysisView/EnvironmentStateExtraction.ts @@ -1,3 +1,4 @@ +import { appendToMapList } from "../appendToMapList.js"; import { StateRecordChronology } from "./StateRecordChronology.js"; import { jsonByteLength } from "../jsonSerialization.js"; import type { JsonValue } from "../jsonValue.js"; @@ -859,9 +860,7 @@ export class EnvironmentStateExtraction { for (const entity of this.#merged.values()) { if (markedDeleted(entity.fields)) continue; const key = environmentCollectionKey(entity.type, entity.collection); - const members = this.#collections.get(key); - if (members === undefined) this.#collections.set(key, [entity]); - else members.push(entity); + appendToMapList(this.#collections, key, entity); } } return ( diff --git a/src/domain/analysisView/WebNetworkApiSurfaceAccumulator.ts b/src/domain/analysisView/WebNetworkApiSurfaceAccumulator.ts index 2f1494042a6..bfa6d808ea9 100644 --- a/src/domain/analysisView/WebNetworkApiSurfaceAccumulator.ts +++ b/src/domain/analysisView/WebNetworkApiSurfaceAccumulator.ts @@ -1,3 +1,4 @@ +import { appendToMapList } from "../appendToMapList.js"; import { mediaTypeEssence } from "./recordedMediaType.js"; import type { AnalysisError } from "../analysisErrorBase.js"; import { compareUnicodeCodePoints as compare } from "../unicodeCodePointOrder.js"; @@ -267,9 +268,7 @@ export class WebNetworkApiSurfaceAccumulator extends WebNetworkProjectionAccumul if (mime !== null) group.contentTypes.add(mime); if (queryNames !== undefined && group.queryNames !== undefined) { for (const name of queryNames) { - const ordinals = group.queryNames.get(name); - if (ordinals === undefined) group.queryNames.set(name, [ordinal]); - else ordinals.push(ordinal); + appendToMapList(group.queryNames, name, ordinal); } } if (group.headers !== undefined && headers !== undefined) @@ -279,9 +278,7 @@ export class WebNetworkApiSurfaceAccumulator extends WebNetworkProjectionAccumul [group.headers.setCookie, headers.setCookie], ] as const) for (const name of selected) { - const ordinals = names.get(name); - if (ordinals === undefined) names.set(name, [ordinal]); - else ordinals.push(ordinal); + appendToMapList(names, name, ordinal); } return ok(undefined); } diff --git a/src/domain/analysisView/artifactInventoryView.ts b/src/domain/analysisView/artifactInventoryView.ts index 317c4aa94b2..478924376b5 100644 --- a/src/domain/analysisView/artifactInventoryView.ts +++ b/src/domain/analysisView/artifactInventoryView.ts @@ -1,3 +1,4 @@ +import { appendToMapList } from "../appendToMapList.js"; import { artifactGraphManifestSchema, artifactInventoryCoverageSchema, @@ -590,12 +591,8 @@ const exactCandidates = ( const byKind = new Map(); for (const [index, row] of rows.entries()) { byId.set(row.occurrence_id, index); - const existing = byPath.get(row.logical_path); - if (existing === undefined) byPath.set(row.logical_path, [index]); - else existing.push(index); - const kind = byKind.get(row.entry_kind); - if (kind === undefined) byKind.set(row.entry_kind, [index]); - else kind.push(index); + appendToMapList(byPath, row.logical_path, index); + appendToMapList(byKind, row.entry_kind, index); } source.index = { byId, byPath, byKind }; } diff --git a/src/domain/analysisView/binaryLayoutView.ts b/src/domain/analysisView/binaryLayoutView.ts index abf8a5b3a91..7aabdc8a6c3 100644 --- a/src/domain/analysisView/binaryLayoutView.ts +++ b/src/domain/analysisView/binaryLayoutView.ts @@ -1,3 +1,4 @@ +import { appendToMapList } from "../appendToMapList.js"; import { analysisViewInputError, invalidAnalysisView, @@ -57,9 +58,7 @@ const layoutNameIndex = ( const row = rows[i]!; if (row.name.unknown_reason !== null || row.name.bytes_base64 === null) continue; - const bucket = built.get(row.name.bytes_base64); - if (bucket === undefined) built.set(row.name.bytes_base64, [i]); - else bucket.push(i); + appendToMapList(built, row.name.bytes_base64, i); } index = built; layoutNameIndexes.set(rows, index); diff --git a/src/domain/analysisView/environmentManifestRules.ts b/src/domain/analysisView/environmentManifestRules.ts index 234b639e068..cbb3575008d 100644 --- a/src/domain/analysisView/environmentManifestRules.ts +++ b/src/domain/analysisView/environmentManifestRules.ts @@ -1,3 +1,4 @@ +import { appendToMapList } from "../appendToMapList.js"; import { compositeKey } from "../unicodeCodePointOrder.js"; import { spelledLikeObserved, @@ -165,9 +166,7 @@ const rebucket = ( group.origin, ...group.parts.map(keyOf), ]); - const bucket = buckets.get(key); - if (bucket === undefined) buckets.set(key, [group]); - else bucket.push(group); + appendToMapList(buckets, key, group); } return [...buckets.values()].map((bucket) => mergeGroups(bucket, shapeOf(bucket)), @@ -296,9 +295,7 @@ const mergeSiblingVariance = (groups: readonly ToolGroup[]): ToolGroup[] => { index === position ? null : partKey(part), ), ]); - const bucket = buckets.get(key); - if (bucket === undefined) buckets.set(key, [group]); - else bucket.push(group); + appendToMapList(buckets, key, group); } for (const bucket of buckets.values()) appendAll(output, mergeSiblings(bucket, position)); @@ -390,9 +387,7 @@ const mergeSiblingPairs = (groups: readonly ToolGroup[]): ToolGroup[] => { index === position || index === position + 1 ? null : partKey(part), ), ]); - const bucket = buckets.get(key); - if (bucket === undefined) buckets.set(key, [group]); - else bucket.push(group); + appendToMapList(buckets, key, group); } for (const bucket of buckets.values()) appendAll(output, mergePairBucket(bucket, position)); diff --git a/src/domain/analysisView/environmentStateInitialOrder.ts b/src/domain/analysisView/environmentStateInitialOrder.ts index 09ed20a3c06..1f67d4fe27c 100644 --- a/src/domain/analysisView/environmentStateInitialOrder.ts +++ b/src/domain/analysisView/environmentStateInitialOrder.ts @@ -1,3 +1,4 @@ +import { appendToMapList } from "../appendToMapList.js"; import { parseUrlQueryParameterNames } from "../recordedTransportUrl.js"; import type { ObservedEntity } from "./environmentStateMerge.js"; import { appliesOrder } from "./environmentStateOrderParameters.js"; @@ -24,9 +25,7 @@ export const orderByWholeLines = ( const collections = new Map(); for (const entity of entities) { const key = `${entity.type}\u0000${entity.collection}`; - const members = collections.get(key); - if (members === undefined) collections.set(key, [entity]); - else members.push(entity); + appendToMapList(collections, key, entity); } for (const members of collections.values()) { const lines = new Map(); diff --git a/src/domain/analysisView/environmentStateListQuery.ts b/src/domain/analysisView/environmentStateListQuery.ts index bfa99c2b604..45c7b76a966 100644 --- a/src/domain/analysisView/environmentStateListQuery.ts +++ b/src/domain/analysisView/environmentStateListQuery.ts @@ -1,3 +1,4 @@ +import { appendToMapList } from "../appendToMapList.js"; import type { JsonValue } from "../jsonValue.js"; import { compareUnicodeCodePoints as compare } from "../unicodeCodePointOrder.js"; import { literalSubstringPredicate } from "../analysisSearch.js"; @@ -497,9 +498,7 @@ const mergeRoles = ( const roles = new Map(); for (const parameters of explained) for (const [name, role] of Object.entries(parameters)) { - const seen = roles.get(name); - if (seen === undefined) roles.set(name, [role]); - else seen.push(role); + appendToMapList(roles, name, role); } // Entries become own members even for names such as `__proto__`, which assignment would treat as the prototype. const merged: [string, QueryParameter][] = []; diff --git a/src/domain/analysisView/environmentStateQueryCalls.ts b/src/domain/analysisView/environmentStateQueryCalls.ts index 3fe172052f5..d74643e9e10 100644 --- a/src/domain/analysisView/environmentStateQueryCalls.ts +++ b/src/domain/analysisView/environmentStateQueryCalls.ts @@ -1,3 +1,4 @@ +import { appendToMapList } from "../appendToMapList.js"; import type { StateRecordChronology } from "./StateRecordChronology.js"; import { digestCanonicalValue } from "../canonicalDigest.js"; import { identifierWords } from "./environmentStateWords.js"; @@ -493,9 +494,7 @@ const changesInStretch = ( ) continue; const line = `${record.path}${record.query ?? ""}`; - const reads = lines.get(line); - if (reads === undefined) lines.set(line, [record]); - else reads.push(record); + appendToMapList(lines, line, record); } // A line whose reads all show one thing cannot change across any call. const changing = [...lines.values()].filter((reads) => { diff --git a/src/domain/analysisView/environmentStateRules.ts b/src/domain/analysisView/environmentStateRules.ts index 478d5c13cee..c375345a827 100644 --- a/src/domain/analysisView/environmentStateRules.ts +++ b/src/domain/analysisView/environmentStateRules.ts @@ -1,3 +1,4 @@ +import { appendToMapList } from "../appendToMapList.js"; import { isSuccessfulHttpStatus } from "../httpResponseStatus.js"; import { isRecord } from "../../kernel/isRecord.js"; import { escapeJsonPointerToken, jsonPointerTokens } from "../jsonPointer.js"; @@ -508,9 +509,7 @@ export const apiBaseLengths = ( for (const template of templates) { const segments = segmentsOf(template); const first = segments[0] ?? ""; - const group = groups.get(first); - if (group === undefined) groups.set(first, [segments]); - else group.push(segments); + appendToMapList(groups, first, segments); } return new Map( [...groups.entries()].map(([first, members]) => { diff --git a/src/domain/analysisView/environmentStateVariants.ts b/src/domain/analysisView/environmentStateVariants.ts index cd732544f9b..e5f43a2a563 100644 --- a/src/domain/analysisView/environmentStateVariants.ts +++ b/src/domain/analysisView/environmentStateVariants.ts @@ -1,3 +1,4 @@ +import { appendToMapList } from "../appendToMapList.js"; import { iterateUrlQueryParameters, parseUrlQueryParameterNames, @@ -51,9 +52,7 @@ export const queryValues = ( ): Map => { const values = new Map(); for (const [name, value] of iterateUrlQueryParameters(query ?? "")) { - const previous = values.get(name); - if (previous === undefined) values.set(name, [value]); - else previous.push(value); + appendToMapList(values, name, value); } return values; }; @@ -138,9 +137,7 @@ const linesByEntity = ( retain(ENTRY_BYTES); const showing = shown.get(key) ?? new Map(); shown.set(key, showing); - const group = showing.get(members); - if (group === undefined) showing.set(members, [line]); - else group.push(line); + appendToMapList(showing, members, line); } return shown; }; diff --git a/src/domain/analysisView/environmentStateWriteComposed.ts b/src/domain/analysisView/environmentStateWriteComposed.ts index 5660f99b062..e6a798b5e0b 100644 --- a/src/domain/analysisView/environmentStateWriteComposed.ts +++ b/src/domain/analysisView/environmentStateWriteComposed.ts @@ -1,3 +1,4 @@ +import { appendToMapList } from "../appendToMapList.js"; import type { JsonValue } from "../jsonValue.js"; import { ownMember, @@ -107,9 +108,7 @@ interface CandidateIndex { const indexed = (candidates: readonly Candidate[]): CandidateIndex => { const byToken = new Map(); for (const candidate of candidates) { - const same = byToken.get(candidate.token); - if (same === undefined) byToken.set(candidate.token, [candidate]); - else same.push(candidate); + appendToMapList(byToken, candidate.token, candidate); } const lengths = [...new Set(candidates.map(({ token }) => token.length))]; return { byToken, lengths: lengths.sort((left, right) => right - left) }; diff --git a/src/domain/analysisView/javascriptApplicationView.ts b/src/domain/analysisView/javascriptApplicationView.ts index 6dcf5d5dcc1..895983881c0 100644 --- a/src/domain/analysisView/javascriptApplicationView.ts +++ b/src/domain/analysisView/javascriptApplicationView.ts @@ -1,3 +1,4 @@ +import { appendToMapList } from "../appendToMapList.js"; import { isImmutableJsonSnapshot } from "../immutableJson.js"; import { isJavaScriptModuleUnit } from "../javascript/javascriptModuleUnits.js"; import { @@ -112,19 +113,13 @@ const buildModuleIndex = (nodes: readonly ApplicationNode[]): ModuleIndex => { byNodeId.has(entry.node.node_id) ? null : entry, ); if (entry.paths.length === 0) { - const existing = nodesByPath.get(null); - if (existing === undefined) nodesByPath.set(null, [entry]); - else existing.push(entry); + appendToMapList(nodesByPath, null, entry); } else { for (const path of entry.paths) { - const existing = nodesByPath.get(path); - if (existing === undefined) nodesByPath.set(path, [entry]); - else existing.push(entry); + appendToMapList(nodesByPath, path, entry); } } - const kindList = nodesByKind.get(entry.node.kind); - if (kindList === undefined) nodesByKind.set(entry.node.kind, [entry]); - else kindList.push(entry); + appendToMapList(nodesByKind, entry.node.kind, entry); } return { moduleEntries: entries, byNodeId, nodesByPath, nodesByKind }; }; diff --git a/src/domain/analysisView/managedMemberView.ts b/src/domain/analysisView/managedMemberView.ts index 2b0774cc7b8..876b13e96b1 100644 --- a/src/domain/analysisView/managedMemberView.ts +++ b/src/domain/analysisView/managedMemberView.ts @@ -1,3 +1,4 @@ +import { appendToMapList } from "../appendToMapList.js"; import { analysisViewInputError, invalidAnalysisView, @@ -85,9 +86,7 @@ const getCollectionFilterIndex = ( const value = row[key]; if (typeof value !== "string") unresolved += 1; else { - const bucket = byValue.get(value); - if (bucket === undefined) byValue.set(value, [index]); - else bucket.push(index); + appendToMapList(byValue, value, index); } } const built = { byValue, unresolved }; diff --git a/src/domain/analysisView/pcapCaptureView.ts b/src/domain/analysisView/pcapCaptureView.ts index 0e059b1d352..1c943892709 100644 --- a/src/domain/analysisView/pcapCaptureView.ts +++ b/src/domain/analysisView/pcapCaptureView.ts @@ -1,3 +1,4 @@ +import { appendToMapList } from "../appendToMapList.js"; import { analysisViewInputError, invalidAnalysisViewSubject, @@ -192,9 +193,7 @@ const indexedDnsQueries = ( if (byName !== undefined) return byName; const grouped = new Map(); for (const entry of capture.dns_queries) { - const existing = grouped.get(entry.query); - if (existing === undefined) grouped.set(entry.query, [entry]); - else existing.push(entry); + appendToMapList(grouped, entry.query, entry); } byName = grouped; dnsQueriesByName.set(capture, byName); diff --git a/src/domain/analysisView/playwrightTraceView.ts b/src/domain/analysisView/playwrightTraceView.ts index 3f6dc308553..95cbf9234fe 100644 --- a/src/domain/analysisView/playwrightTraceView.ts +++ b/src/domain/analysisView/playwrightTraceView.ts @@ -1,3 +1,4 @@ +import { appendToMapList } from "../appendToMapList.js"; import { analysisTextPage, analysisTextPageItemSchema, @@ -178,9 +179,7 @@ const candidateIndices = ( for (let i = 0; i < rows.length; i += 1) { const value = rows[i]?.[key]; if (typeof value !== "string") continue; - const bucket = built.get(value); - if (bucket === undefined) built.set(value, [i]); - else bucket.push(i); + appendToMapList(built, value, i); } index = built; indexes.set(key, index); diff --git a/src/domain/artifactComparison.ts b/src/domain/artifactComparison.ts index 047f3841355..538fcac9fb9 100644 --- a/src/domain/artifactComparison.ts +++ b/src/domain/artifactComparison.ts @@ -1,3 +1,4 @@ +import { appendToMapList } from "./appendToMapList.js"; import { compareUnicodeCodePoints } from "./unicodeCodePointOrder.js"; import { z } from "zod"; @@ -441,10 +442,7 @@ const occurrencesByPath = ( ): ReadonlyMap => { const output = new Map(); for (const occurrence of occurrences) { - const matches = output.get(occurrence.logical_path); - if (matches === undefined) - output.set(occurrence.logical_path, [occurrence]); - else matches.push(occurrence); + appendToMapList(output, occurrence.logical_path, occurrence); } return output; }; diff --git a/src/domain/artifactInventoryEvidence.ts b/src/domain/artifactInventoryEvidence.ts index e7ee97ad696..0a125138479 100644 --- a/src/domain/artifactInventoryEvidence.ts +++ b/src/domain/artifactInventoryEvidence.ts @@ -1,3 +1,4 @@ +import { appendToMapList } from "./appendToMapList.js"; import { canBorrowParsedJsonSnapshot, isImmutableJsonSnapshot, @@ -596,9 +597,7 @@ const orderOccurrences = ( ): ArtifactOccurrence[] => { const groups = new Map(); for (const occurrence of occurrences) { - const group = groups.get(occurrence.logical_path); - if (group === undefined) groups.set(occurrence.logical_path, [occurrence]); - else group.push(occurrence); + appendToMapList(groups, occurrence.logical_path, occurrence); } return [...groups] .sort(([left], [right]) => compareUnicodeCodePoints(left, right)) diff --git a/src/domain/desktop/positionalKeys.ts b/src/domain/desktop/positionalKeys.ts index d8df7690869..dba76cc44f2 100644 --- a/src/domain/desktop/positionalKeys.ts +++ b/src/domain/desktop/positionalKeys.ts @@ -1,3 +1,4 @@ +import { appendToMapList } from "../appendToMapList.js"; import type { JsonValue } from "../jsonValue.js"; import { isIdentifyingAttribute } from "./attributeRank.js"; import { isRecord } from "../../kernel/isRecord.js"; @@ -16,9 +17,7 @@ const attributesByTag = (items: readonly JsonValue[]) => { (entry): entry is [string, string] => typeof entry[1] === "string", ), ); - const members = byTag.get(item.name); - if (members === undefined) byTag.set(item.name, [strings]); - else members.push(strings); + appendToMapList(byTag, item.name, strings); } return byTag; }; diff --git a/src/domain/desktop/viewPointer.ts b/src/domain/desktop/viewPointer.ts index 5b0db00c47e..0fdc09239de 100644 --- a/src/domain/desktop/viewPointer.ts +++ b/src/domain/desktop/viewPointer.ts @@ -1,3 +1,4 @@ +import { appendToMapList } from "../appendToMapList.js"; import { unescapeJsonPointerToken } from "../jsonPointer.js"; import type { JsonValue } from "../jsonValue.js"; import { collapseWhitespace, isTimestamp } from "./appTask.js"; @@ -301,9 +302,7 @@ const selectorGroups = (tokens: Iterable) => { const values = JSON.stringify(conditions.map(({ value }) => value)); const group = groups.get(fields) ?? { conditions, wanted: new Map() }; groups.set(fields, group); - const spellings = group.wanted.get(values); - if (spellings === undefined) group.wanted.set(values, [token]); - else spellings.push(token); + appendToMapList(group.wanted, values, token); } return groups.values(); }; diff --git a/src/domain/functionComparisonDimensions.ts b/src/domain/functionComparisonDimensions.ts index b80e576d8fb..0af8905342c 100644 --- a/src/domain/functionComparisonDimensions.ts +++ b/src/domain/functionComparisonDimensions.ts @@ -1,3 +1,4 @@ +import { appendToMapList } from "./appendToMapList.js"; import { hasStableNativeSymbol } from "./native/nativeSymbol.js"; import { canonicalJson } from "./comparisonSemantics.js"; import { @@ -512,9 +513,7 @@ const groupStringsByContent = ( const groups = new Map(); for (const string of strings) { if (string.content === null) continue; - const rows = groups.get(string.content); - if (rows === undefined) groups.set(string.content, [string]); - else rows.push(string); + appendToMapList(groups, string.content, string); } return groups; }; @@ -536,9 +535,7 @@ const groupStringsByOffset = ( ): Map => { const groups = new Map(); for (const string of strings) { - const rows = groups.get(string.source_offset); - if (rows === undefined) groups.set(string.source_offset, [string]); - else rows.push(string); + appendToMapList(groups, string.source_offset, string); } return groups; }; diff --git a/src/domain/javascript/electronWrappedCallPaths.ts b/src/domain/javascript/electronWrappedCallPaths.ts index 305aac7d226..f6934faf81a 100644 --- a/src/domain/javascript/electronWrappedCallPaths.ts +++ b/src/domain/javascript/electronWrappedCallPaths.ts @@ -1,3 +1,4 @@ +import { appendToMapList } from "../appendToMapList.js"; import * as t from "@babel/types"; import { runtimeFunctionParameters } from "./javascriptAstValues.js"; import { JavaScriptSymbolicBindings } from "./javascriptSymbolicBindings.js"; @@ -183,9 +184,7 @@ const indexIpcFinding = ( facts.reached.get(valueKey) ?? new Map(); facts.reached.set(valueKey, byLast); const last = reached.calls.at(-1) ?? ""; - const chains = byLast.get(last); - if (chains === undefined) byLast.set(last, [reached]); - else chains.push(reached); + appendToMapList(byLast, last, reached); } }; diff --git a/src/domain/javascript/javascriptApplicationVersionKeys.ts b/src/domain/javascript/javascriptApplicationVersionKeys.ts index 8d33a294775..8d167e8393a 100644 --- a/src/domain/javascript/javascriptApplicationVersionKeys.ts +++ b/src/domain/javascript/javascriptApplicationVersionKeys.ts @@ -1,3 +1,4 @@ +import { appendToMapList } from "../appendToMapList.js"; import { nativeExportCorrespondenceKey } from "./javascriptNativeExportFacts.js"; import { canonicalJson } from "../comparisonSemantics.js"; import { @@ -155,9 +156,7 @@ const nodesByKey = ( for (const node of nodes) { const key = keyFor(node); if (key === null) continue; - const group = output.get(key); - if (group === undefined) output.set(key, [node]); - else group.push(node); + appendToMapList(output, key, node); } return output; }; diff --git a/src/domain/javascript/javascriptFeatureTrace.ts b/src/domain/javascript/javascriptFeatureTrace.ts index 5060c095554..7c45f44db1c 100644 --- a/src/domain/javascript/javascriptFeatureTrace.ts +++ b/src/domain/javascript/javascriptFeatureTrace.ts @@ -1,3 +1,4 @@ +import { appendToMapList } from "../appendToMapList.js"; import { isImmutableJsonSnapshot } from "../immutableJson.js"; import { digestCanonicalValue } from "../canonicalDigest.js"; import { uniqueSorted } from "../canonicalOrdering.js"; @@ -234,9 +235,7 @@ const getSemanticLabelCaseCache = ( texts.push(normalized); if (!seenTexts.has(normalized)) { seenTexts.add(normalized); - const bucket = byExact.get(normalized); - if (bucket === undefined) byExact.set(normalized, [entry.match]); - else bucket.push(entry.match); + appendToMapList(byExact, normalized, entry.match); } } normalizedEntries.push({ match: entry.match, texts }); diff --git a/src/domain/javascript/javascriptRuntimeStaticCandidates.ts b/src/domain/javascript/javascriptRuntimeStaticCandidates.ts index e8a9c1bf5be..71514a1e11d 100644 --- a/src/domain/javascript/javascriptRuntimeStaticCandidates.ts +++ b/src/domain/javascript/javascriptRuntimeStaticCandidates.ts @@ -1,3 +1,4 @@ +import { appendToMapList } from "../appendToMapList.js"; import { isJavaScriptModuleUnit, isJavaScriptSourceModule, @@ -181,10 +182,7 @@ const indexStaticPaths = ( if (edge.relation !== "maps_to") continue; const target = nodes.get(edge.target_node_id); if (target === undefined) continue; - const related = relatedBySource.get(edge.source_node_id); - if (related === undefined) - relatedBySource.set(edge.source_node_id, [target]); - else related.push(target); + appendToMapList(relatedBySource, edge.source_node_id, target); } return new Map( graph.nodes.map((node) => [ diff --git a/src/domain/javascript/javascriptSemanticFingerprints.ts b/src/domain/javascript/javascriptSemanticFingerprints.ts index 6fbcae01386..a3381d96abf 100644 --- a/src/domain/javascript/javascriptSemanticFingerprints.ts +++ b/src/domain/javascript/javascriptSemanticFingerprints.ts @@ -1,3 +1,4 @@ +import { appendToMapList } from "../appendToMapList.js"; import * as t from "@babel/types"; import { runtimeFunctionParameters } from "./javascriptAstValues.js"; @@ -157,9 +158,7 @@ const groupByOwner = ( const grouped = new Map(); for (const value of values) { const owner = getOwner(value); - const ownedValues = grouped.get(owner); - if (ownedValues === undefined) grouped.set(owner, [value]); - else ownedValues.push(value); + appendToMapList(grouped, owner, value); } return grouped; }; diff --git a/src/domain/javascript/javascriptSemanticObjectReferences.ts b/src/domain/javascript/javascriptSemanticObjectReferences.ts index 2e700e5103a..4b9abd32bba 100644 --- a/src/domain/javascript/javascriptSemanticObjectReferences.ts +++ b/src/domain/javascript/javascriptSemanticObjectReferences.ts @@ -1,3 +1,4 @@ +import { appendToMapList } from "../appendToMapList.js"; import * as t from "@babel/types"; import { semanticKnownSymbolKey } from "./javascriptSemanticPropertyKeys.js"; import { @@ -572,9 +573,7 @@ const objectPropertyIndex = (node: t.ObjectExpression): ObjectPropertyIndex => { keyIndependent.push(index); return; } - const positions = byName.get(name); - if (positions === undefined) byName.set(name, [index]); - else positions.push(index); + appendToMapList(byName, name, index); }); const index = { keyIndependent, byName }; propertyIndexes.set(node, index); diff --git a/src/domain/managed/managedMemberComparison.ts b/src/domain/managed/managedMemberComparison.ts index 2269329e063..ac7e76e650f 100644 --- a/src/domain/managed/managedMemberComparison.ts +++ b/src/domain/managed/managedMemberComparison.ts @@ -1,3 +1,4 @@ +import { appendToMapList } from "../appendToMapList.js"; import { z } from "zod"; import { digestCanonicalValue } from "../canonicalDigest.js"; @@ -281,9 +282,7 @@ const callEdgesByCaller = ( ManagedMemberInspection["call_edges"][number][] >(); for (const edge of result.call_edges) { - const callerEdges = edges.get(edge.caller_token); - if (callerEdges === undefined) edges.set(edge.caller_token, [edge]); - else callerEdges.push(edge); + appendToMapList(edges, edge.caller_token, edge); } return edges; }; @@ -305,10 +304,7 @@ const fieldAccessesByCaller = ( access.target_identity_sha256 !== null ? { ...access, target_identity_sha256: null } : access; - const callerAccesses = accesses.get(access.method_token); - if (callerAccesses === undefined) - accesses.set(access.method_token, [observed]); - else callerAccesses.push(observed); + appendToMapList(accesses, access.method_token, observed); } return accesses; }; diff --git a/src/domain/managed/managedMemberComparisonCoverage.ts b/src/domain/managed/managedMemberComparisonCoverage.ts index fa0f03babc4..4fdf87946dc 100644 --- a/src/domain/managed/managedMemberComparisonCoverage.ts +++ b/src/domain/managed/managedMemberComparisonCoverage.ts @@ -1,3 +1,4 @@ +import { appendToMapList } from "../appendToMapList.js"; import { managedModuleRow } from "./managedModuleIdentity.js"; import { joinCoverageStatus } from "../coverage.js"; import type { @@ -72,9 +73,7 @@ const unavailableTypeNames = ( const children = new Map(); for (const { token, enclosing_type_token: enclosing } of types) { if (enclosing === null) continue; - const existing = children.get(enclosing); - if (existing === undefined) children.set(enclosing, [token]); - else existing.push(token); + appendToMapList(children, enclosing, token); } // A Set visits appended entries and prevents cyclic historical links from // revisiting a row. Follow only enclosing links retained in the report. diff --git a/src/domain/native/nativeInvestigationGraph.ts b/src/domain/native/nativeInvestigationGraph.ts index 6957ec9b9ad..4d3f7bcc827 100644 --- a/src/domain/native/nativeInvestigationGraph.ts +++ b/src/domain/native/nativeInvestigationGraph.ts @@ -1,3 +1,4 @@ +import { appendToMapList } from "../appendToMapList.js"; import { z } from "zod"; import { coverageStatusSchema } from "../coverage.js"; @@ -231,9 +232,7 @@ export const traceNativeInvestigationGraph = ( for (const edge of graph.edges) { const nodeId = direction === "forward" ? edge.from : edge.to; if (nodeId === null) continue; - const entries = adjacency.get(nodeId); - if (entries === undefined) adjacency.set(nodeId, [edge]); - else entries.push(edge); + appendToMapList(adjacency, nodeId, edge); } let queueHead = 0; @@ -320,9 +319,7 @@ const indexTargetActionEdges = ( continue; if (nodes.get(edge.to)?.kind === "objc_selector") selectorNodesByAction.set(edge.from, edge.to); - const list = edgesByAction.get(edge.from); - if (list === undefined) edgesByAction.set(edge.from, [edge]); - else list.push(edge); + appendToMapList(edgesByAction, edge.from, edge); } return { selectorNodesByAction, edgesByAction }; }; @@ -340,19 +337,13 @@ const indexInstanceImplementations = ( >(); for (const candidate of implementations) { if (candidate.method_type !== "instance") continue; - const selectorCandidates = bySelector.get(candidate.selector); - if (selectorCandidates === undefined) - bySelector.set(candidate.selector, [candidate]); - else selectorCandidates.push(candidate); + appendToMapList(bySelector, candidate.selector, candidate); let byClass = bySelectorAndClass.get(candidate.selector); if (byClass === undefined) { byClass = new Map(); bySelectorAndClass.set(candidate.selector, byClass); } - const classCandidates = byClass.get(candidate.class_name); - if (classCandidates === undefined) - byClass.set(candidate.class_name, [candidate]); - else classCandidates.push(candidate); + appendToMapList(byClass, candidate.class_name, candidate); } return { bySelector, bySelectorAndClass }; }; diff --git a/src/domain/reconstructionCoverage.ts b/src/domain/reconstructionCoverage.ts index daef9f6b921..a6fac8233b3 100644 --- a/src/domain/reconstructionCoverage.ts +++ b/src/domain/reconstructionCoverage.ts @@ -1,3 +1,4 @@ +import { appendToMapList } from "./appendToMapList.js"; import { reconstructionCoverageScope } from "./reconstructionCoverageScope.js"; import { z } from "zod"; import { AnalysisInputError } from "./analysisErrorCore.js"; @@ -423,9 +424,7 @@ const validateCoverageReferences = ( ["owners", index, "surface_id"], `Owner surface is missing: ${owner.surface_id}`, ); - const owners = ownersBySurface.get(owner.surface_id); - if (owners === undefined) ownersBySurface.set(owner.surface_id, [owner]); - else owners.push(owner); + appendToMapList(ownersBySurface, owner.surface_id, owner); } for (const [index, claim] of workspace.claims.entries()) { const missingSurface = claim.surface_ids.findIndex( diff --git a/src/domain/reconstructionCoverageEvaluation.ts b/src/domain/reconstructionCoverageEvaluation.ts index 64a7e180efb..a646d95ebf8 100644 --- a/src/domain/reconstructionCoverageEvaluation.ts +++ b/src/domain/reconstructionCoverageEvaluation.ts @@ -1,3 +1,4 @@ +import { appendToMapList } from "./appendToMapList.js"; import { reconstructionUnknownHeads } from "./reconstructionUnknowns.js"; import type { ReconstructionCoverageScope } from "./reconstructionCoverageScope.js"; import type { @@ -454,9 +455,7 @@ export const evaluateReconstructionPackageProofs = ( ReconstructionCoverageData["package_proofs"][number][] >(); for (const proof of context.coverage.package_proofs) { - const bucket = proofsByKind.get(proof.kind); - if (bucket === undefined) proofsByKind.set(proof.kind, [proof]); - else bucket.push(proof); + appendToMapList(proofsByKind, proof.kind, proof); } for (const kind of context.boundary.required_package_proof_kinds) { const proofs = proofsByKind.get(kind) ?? []; diff --git a/src/domain/reconstructionVerification.ts b/src/domain/reconstructionVerification.ts index 11d5e04addf..178f1b0b0c1 100644 --- a/src/domain/reconstructionVerification.ts +++ b/src/domain/reconstructionVerification.ts @@ -1,3 +1,4 @@ +import { appendToMapList } from "./appendToMapList.js"; import { isDeepStrictEqual } from "node:util"; import { evidenceFileTarget, evidenceLocalTarget } from "./evidence.js"; @@ -329,9 +330,7 @@ const indexScreenshotCaptures = (records: Iterable) => { evidenceId: source.evidence_id, screenshot: parsed.value, }; - const existing = captures.get(sha256); - if (existing === undefined) captures.set(sha256, [capture]); - else existing.push(capture); + appendToMapList(captures, sha256, capture); } return captures; }; diff --git a/src/domain/rust/rustBinary.ts b/src/domain/rust/rustBinary.ts index 3a42ea64643..2ae4a36eea8 100644 --- a/src/domain/rust/rustBinary.ts +++ b/src/domain/rust/rustBinary.ts @@ -1,3 +1,4 @@ +import { appendToMapList } from "../appendToMapList.js"; import { z } from "zod"; import { RUST_PRODUCER_DEFAULTS, @@ -282,9 +283,7 @@ const checkPackages = ( ); continue; } - const grouped = edgesByPackage.get(edge.from_index); - if (grouped === undefined) edgesByPackage.set(edge.from_index, [edge]); - else grouped.push(edge); + appendToMapList(edgesByPackage, edge.from_index, edge); } for (const [packageIndex, pkg] of metadata.packages.entries()) { if (pkg.root) roots.push(packageIndex); diff --git a/src/domain/symbolAnalysis.ts b/src/domain/symbolAnalysis.ts index 0526f6dce43..c5ca7403f2a 100644 --- a/src/domain/symbolAnalysis.ts +++ b/src/domain/symbolAnalysis.ts @@ -1,3 +1,4 @@ +import { appendToMapList } from "./appendToMapList.js"; import { objcClassSymbol, objcSymbolLeaf } from "./objcClassSymbol.js"; import type { JsonValue } from "./jsonValue.js"; import type { AddressedName } from "./native/nativeInventory.js"; @@ -188,9 +189,7 @@ const swiftAliasesByAddress = (symbols: readonly AddressedName[]) => { const aliases = new Map(); for (const { address, name } of symbols) { if (!isSwiftSymbolName(name)) continue; - const existing = aliases.get(address); - if (existing === undefined) aliases.set(address, [name]); - else existing.push(name); + appendToMapList(aliases, address, name); } return aliases; }; diff --git a/src/domain/webInventory.ts b/src/domain/webInventory.ts index b98efb56ea2..cf9b24ba753 100644 --- a/src/domain/webInventory.ts +++ b/src/domain/webInventory.ts @@ -1,3 +1,4 @@ +import { appendToMapList } from "./appendToMapList.js"; import { digestCanonicalValue } from "./canonicalDigest.js"; import { compareUnicodeCodePoints } from "./unicodeCodePointOrder.js"; @@ -84,10 +85,7 @@ export const createCapturedWebScriptReconciler = ( ); const keysByUrl = new Map(); for (const resource of resources) { - const keys = keysByUrl.get(resource.url); - if (keys === undefined) - keysByUrl.set(resource.url, [resource.resource_key]); - else keys.push(resource.resource_key); + appendToMapList(keysByUrl, resource.url, resource.resource_key); } for (const [url, keys] of keysByUrl) if (keys.length > 1) keysByUrl.set(url, [...new Set(keys)].sort()); diff --git a/src/dotnet/ManagedFieldConstants.ts b/src/dotnet/ManagedFieldConstants.ts index 59f99f78a6d..c07e8bf7f21 100644 --- a/src/dotnet/ManagedFieldConstants.ts +++ b/src/dotnet/ManagedFieldConstants.ts @@ -1,3 +1,4 @@ +import { appendToMapList } from "../domain/appendToMapList.js"; import type { ManagedParseIssue } from "../domain/managed/managedArtifact.js"; import type { ManagedFieldConstant } from "../domain/managed/managedFieldConstant.js"; import { @@ -67,9 +68,7 @@ const fieldConstantDeclarations = ( padding: typeAndPadding >>> 8, blob_index: blobIndex, }; - const previous = result.get(parent.row); - if (previous === undefined) result.set(parent.row, [declaration]); - else previous.push(declaration); + appendToMapList(result, parent.row, declaration); } return result; }; diff --git a/src/il2cpp/Il2cppBinaryGenerics.ts b/src/il2cpp/Il2cppBinaryGenerics.ts index ef3c31e2432..fabdf8bf9b7 100644 --- a/src/il2cpp/Il2cppBinaryGenerics.ts +++ b/src/il2cpp/Il2cppBinaryGenerics.ts @@ -1,3 +1,4 @@ +import { appendToMapList } from "../domain/appendToMapList.js"; import type { Il2cppGenericMethodInstance } from "../domain/il2cpp/il2cppMetadata.js"; import { Il2cppBinaryFormatFailure } from "./Il2cppBinaryFormat.js"; import { @@ -240,9 +241,7 @@ export function* linkGenericMethodsSteps( for (let row = 0; row < tableCount; row++) { if (row % BATCH === 0) yield; const spec = i32(rowAt(row))!; - const rows = specRows.get(spec); - if (rows === undefined) specRows.set(spec, [row]); - else rows.push(row); + appendToMapList(specRows, spec, row); } const issues: Il2cppGenericMethodIssue[] = []; const issue = (row: number, address: bigint, message: string) => { diff --git a/src/resources/ArtifactPaths.ts b/src/resources/ArtifactPaths.ts index 12854d92359..2a465de5ca4 100644 --- a/src/resources/ArtifactPaths.ts +++ b/src/resources/ArtifactPaths.ts @@ -1,3 +1,4 @@ +import { appendToMapList } from "../domain/appendToMapList.js"; import { posix } from "node:path"; import { logicalPathNfc } from "../domain/artifactIdentity.js"; @@ -328,9 +329,7 @@ const englishUnicodeCaseCollisions = ( let child = node.bySpelling.get(part); if (child === undefined) { const folded = englishCaseFold(part); - const spellings = node.spellingsByFold.get(folded); - if (spellings === undefined) node.spellingsByFold.set(folded, [part]); - else spellings.push(part); + appendToMapList(node.spellingsByFold, folded, part); child = emptyCaseNode(); node.bySpelling.set(part, child); }