Skip to content

Commit

Permalink
Further simplify
Browse files Browse the repository at this point in the history
  • Loading branch information
ericglau committed Sep 12, 2023
1 parent 485bf92 commit 0c2970a
Showing 1 changed file with 9 additions and 16 deletions.
25 changes: 9 additions & 16 deletions packages/core/src/storage/namespace.ts
Original file line number Diff line number Diff line change
Expand Up @@ -90,15 +90,10 @@ function loadNamespacesWithSrcs(
) {
const result: Record<string, NamespaceWithSrcs> = {};

const id = origContext.contractDef.id;
const origLinearizedIds = origContext.contractDef.linearizedBaseContracts;
if (namespacedContext === undefined) {
for (let i = 0; i < origLinearizedIds.length; i++) {
const parentId = origLinearizedIds[i];

// Avoids an extra dereference for the original contract
const origInherit =
parentId === id ? origContext.contractDef : origContext.deref(['ContractDefinition'], parentId);
const origInherit = getReferencedContract(origLinearizedIds[i], origContext);

pushNamespacesForSingleContract(
result,
Expand All @@ -112,16 +107,8 @@ function loadNamespacesWithSrcs(
const namespacedLinearizedIds = namespacedContext.contractDef.linearizedBaseContracts;
assert(origLinearizedIds.length === namespacedLinearizedIds.length);
for (let i = 0; i < origLinearizedIds.length; i++) {
const parentId = origLinearizedIds[i];
const namespacedParentId = namespacedLinearizedIds[i];

// Avoids an extra dereference for the original contract
const origInherit =
parentId === id ? origContext.contractDef : origContext.deref(['ContractDefinition'], parentId);
const namespacedInherit =
namespacedParentId === id
? namespacedContext.contractDef
: namespacedContext.deref(['ContractDefinition'], namespacedParentId);
const origInherit = getReferencedContract(origLinearizedIds[i], origContext);
const namespacedInherit = getReferencedContract(namespacedLinearizedIds[i], namespacedContext);

pushNamespacesForSingleContract(
result,
Expand All @@ -136,6 +123,12 @@ function loadNamespacesWithSrcs(
return result;
}

function getReferencedContract(referencedId: number, context: CompilationContext) {
return context.contractDef.id === referencedId
? context.contractDef
: context.deref(['ContractDefinition'], referencedId);
}

function pushNamespacesForSingleContract(
namespaces: Record<string, NamespaceWithSrcs>,
decodeSrc: SrcDecoder,
Expand Down

0 comments on commit 0c2970a

Please sign in to comment.