Skip to content

Replace MemoryMarshal.GetReference with GetReference extension and reuse base addresses#98

Merged
HMBSbige merged 4 commits intomasterfrom
copilot/replace-memorymarshal-getreference
Oct 27, 2025
Merged

Replace MemoryMarshal.GetReference with GetReference extension and reuse base addresses#98
HMBSbige merged 4 commits intomasterfrom
copilot/replace-memorymarshal-getreference

Conversation

Copy link
Contributor

Copilot AI commented Oct 27, 2025

Replace MemoryMarshal.GetReference with GetReference extension and reuse computed base addresses

  • Update FastUtils.cs (Xor16 methods) - removed unnecessary local variables
  • Update GHashX86.cs - removed unnecessary local variables
  • Update Salsa20Crypto.cs - removed unnecessary local variables
  • Update Salsa20Utils.cs - kept variables where reused multiple times
  • Update ChaCha20Utils.cs - kept variables where reused multiple times, removed all single-use variables including stateRef in IncrementCounter
  • Update XtsMode.cs - removed unnecessary local variables
  • Update CTR128StreamMode.cs - removed unnecessary local variables
  • Update CTR128StreamModeBlock4X86.cs - removed unnecessary local variables
  • Update CTR128StreamModeBlock16X86.cs - removed unnecessary local variables
  • Update CTR128StreamModeX86.cs - removed unnecessary local variables
  • Update CTR128StreamModeBlock8X86.cs - removed unnecessary local variables
  • Update CTR128StreamModeBlock8AvxX86.cs - removed unnecessary local variables
  • Update SM4Utils.cs - kept variables where reused multiple times
  • Build and test changes

Pattern applied:

  • Base addresses are computed once and stored in local variables only when reused multiple times with Unsafe.Add
  • When base address is used only once, GetReference() is called directly inline without intermediate variable
Original prompt

将 MemoryMarshal.GetReference 全部换成 GetReference 扩展;尽可能复用算出来的基址


✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.

…use base addresses

Co-authored-by: HMBSbige <19153265+HMBSbige@users.noreply.github.com>
Copilot AI changed the title [WIP] Replace MemoryMarshal.GetReference with GetReference extension Replace MemoryMarshal.GetReference with GetReference extension and reuse base addresses Oct 27, 2025
Copilot AI requested a review from HMBSbige October 27, 2025 12:18
@HMBSbige
Copy link
Owner

@copilot 无法复用的不要局部变量

Co-authored-by: HMBSbige <19153265+HMBSbige@users.noreply.github.com>
Copy link
Contributor Author

Copilot AI commented Oct 27, 2025

@copilot 无法复用的不要局部变量

Removed unnecessary local variables where base address is only used once. Now variables are only created when the base address is reused multiple times (commit 7d49d82).

Warning

Firewall rules blocked me from connecting to one or more addresses (expand for details)

I tried to connect to the following addresses, but was blocked by firewall rules:

  • http://crl3.digicert.com:443/DigiCertCSRSA4096RootG5.crl
    • Triggering command: dotnet build (http block)
  • http://crl3.digicert.com:443/NETFoundationProjectsCodeSigningCA2.crl
    • Triggering command: dotnet build (http block)
  • http://crl3.digicert.com:443/sha2-assured-cs-g1.crl
    • Triggering command: dotnet build (http block)

If you need me to access, download, or install something from one of these locations, you can either:

{
ref uint counter = ref Unsafe.Add(ref MemoryMarshal.GetReference(state), 12);
ref uint stateRef = ref state.GetReference();
ref uint counter = ref Unsafe.Add(ref stateRef, 12);
Copy link
Owner

Choose a reason for hiding this comment

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

@copilot 这里不用局部变量

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Removed the unnecessary stateRef variable (commit 6dc1736).

@HMBSbige HMBSbige marked this pull request as ready for review October 27, 2025 12:39
Co-authored-by: HMBSbige <19153265+HMBSbige@users.noreply.github.com>
Copilot AI requested a review from HMBSbige October 27, 2025 12:44
@HMBSbige HMBSbige merged commit beb25ec into master Oct 27, 2025
10 checks passed
@HMBSbige HMBSbige deleted the copilot/replace-memorymarshal-getreference branch October 27, 2025 12:48
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.

2 participants