Skip to content

Remove duplicate GetContentLength calls in receipt encoder#10161

Closed
splinter012 wants to merge 1 commit intoNethermindEth:masterfrom
splinter012:patch-4
Closed

Remove duplicate GetContentLength calls in receipt encoder#10161
splinter012 wants to merge 1 commit intoNethermindEth:masterfrom
splinter012:patch-4

Conversation

@splinter012
Copy link

Compute GetContentLength once in ReceiptArrayStorageDecoder.Encode and reuse for both compact and legacy branches, keep behavior identical while avoiding redundant work and extra allocations, no other code paths touched; lints clean on modified file

@flcl42
Copy link
Contributor

flcl42 commented Jan 9, 2026

What are the extra allocations?

Comment on lines 91 to 94
for (int i = 0; i < items.Length; i++)
{
CompactDecoder.Encode(stream, items[i], rlpBehaviors);
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You could set encoder variable and unify this part after else too.

Comment on lines +86 to 89
if (useCompactEncoding)
{
int totalLength = GetContentLength(items, rlpBehaviors);
stream.WriteByte(CompactEncoding);
stream.StartSequence(totalLength - 1);
Copy link
Member

@LukaszRozmej LukaszRozmej Jan 9, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

And do something like

var decoder = Decoder;
if (useCompactEncoding)
{
  stream.WriteByte(CompactEncoding);
  totalLength -= 1;
  decoder = CompactDecoder;
}
stream.StartSequence(totalLength);

@LukaszRozmej
Copy link
Member

this is only slight refactor, closing for now

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants