This repository has been archived by the owner on Jan 23, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 4.9k
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
In particular after dotnet/coreclr#3118, Buffer.BlockCopy has less overhead than Array.Copy when copying byte[]s, such that there's no benefit to using Array.Copy and potential benefit to using Buffer.BlockCopy. This commit replaces usage of Array.Copy(byte[], ...) in corefx with Buffer.BlockCopy(byte[], ...). A lot of places were already using it. (In a few places where we weren't passing lower bounds to Array.Copy with T[] arguments, I added explicit lower bounds as well to avoid the overload needing to call GetLowerBound.)
stephentoub
force-pushed
the
buffer_blockcopy
branch
from
February 14, 2016 14:04
b56c533
to
3ab3bd6
Compare
LGTM for networking |
Security (including parts in Common) LGTM |
@@ -186,7 +186,7 @@ public char[] Value | |||
|
|||
default: | |||
buffer = new char[_lCurLen]; | |||
Array.Copy(m_rgchBuf, buffer, (int)_lCurLen); | |||
Array.Copy(m_rgchBuf, 0, buffer, 0, (int)_lCurLen); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Did you leave this out to use Array.Copy intentionally?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, I was only changing those using byte[] to use BlockCopy.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah OK.
LGTM from data |
stephentoub
added a commit
that referenced
this pull request
Feb 15, 2016
Use Buffer.BlockCopy with byte[]s
bgrainger
added a commit
to mysql-net/MySqlConnector
that referenced
this pull request
Apr 22, 2016
See discussion at dotnet/corefx#6103.
picenka21
pushed a commit
to picenka21/runtime
that referenced
this pull request
Feb 18, 2022
Use Buffer.BlockCopy with byte[]s Commit migrated from dotnet/corefx@59f4427
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
In particular after dotnet/coreclr#3118, Buffer.BlockCopy has less overhead than Array.Copy when copying byte[]s, such that there's no benefit to using Array.Copy and potential benefit to using Buffer.BlockCopy (in particular for small arrays).
This commit replaces usage of Array.Copy(byte[], ...) in corefx with Buffer.BlockCopy(byte[], ...). A lot of places were already using BlockCopy.
(In a few places where we weren't passing lower bounds to Array.Copy with T[] arguments, I added explicit lower bounds as well to avoid the overload needing to call GetLowerBound.)
cc:
@davidsh for networking
@saurabh500 for data
@bartonjs for security
@ianhays for I/O