New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Use Enumerable.Empty and Array.Empty #4654
Conversation
These return singleton instances, so reduce overall allocations. Also use `new []` over `new List` in a few places, for lesser allocations.
Depends on if you are going to remove or add items. Also there is toarray
on ienumerable.
…On Sat, Mar 17, 2018, 3:01 PM Drew Noakes ***@***.***> wrote:
Enumerable.Empty and Array.Empty return singleton instances, so reduce
overall allocations.
Also use new [] { ... } over new List<T> { ... } in a few places, for
lesser allocations. The latter allocates an over-sized array (capacity 16)
as well as the overhead of List<T>.
In a few places I substitute in IReadOnlyList<T>. I feel like GE could
use this interface more broadly, though understand the interface itself is
newer than much of the codebase. I will use it more in future.
What did I do to test the code and ensure quality:
- Manual review of straightforward changes. The compiler does the
checking here.
------------------------------
You can view, comment on, or merge this pull request online at:
#4654
Commit Summary
- Use Enumerable.Empty and Array.Empty
File Changes
- *M* GitCommands/Config/ConfigFile.cs
<https://github.com/gitextensions/gitextensions/pull/4654/files#diff-0>
(2)
- *M* GitCommands/ExternalLinks/ExternalLinksLoader.cs
<https://github.com/gitextensions/gitextensions/pull/4654/files#diff-1>
(4)
- *M* GitCommands/Git/GitModule.cs
<https://github.com/gitextensions/gitextensions/pull/4654/files#diff-2>
(12)
- *M* GitUI/CommandsDialogs/BrowseDialog/FormBrowseMenus.cs
<https://github.com/gitextensions/gitextensions/pull/4654/files#diff-3>
(4)
- *M* GitUI/CommandsDialogs/RepoHosting/ViewPullRequestsForm.cs
<https://github.com/gitextensions/gitextensions/pull/4654/files#diff-4>
(6)
- *M* GitUI/UserControls/RevisionGrid.cs
<https://github.com/gitextensions/gitextensions/pull/4654/files#diff-5>
(2)
- *M* Plugins/GitFlow/GitFlowForm.cs
<https://github.com/gitextensions/gitextensions/pull/4654/files#diff-6>
(12)
- *M*
Plugins/GitUIPluginInterfaces/RepositoryHosts/IHostedRepository.cs
<https://github.com/gitextensions/gitextensions/pull/4654/files#diff-7>
(2)
- *M* Plugins/Github3/GithubRepo.cs
<https://github.com/gitextensions/gitextensions/pull/4654/files#diff-8>
(8)
- *M* ResourceManager/GitPluginBase.cs
<https://github.com/gitextensions/gitextensions/pull/4654/files#diff-9>
(3)
- *M* ResourceManager/Translator.cs
<https://github.com/gitextensions/gitextensions/pull/4654/files#diff-10>
(2)
- *M*
UnitTests/GitUITests/UserControls/AuthorEmailBasedRevisionHighlightingFixture.cs
<https://github.com/gitextensions/gitextensions/pull/4654/files#diff-11>
(4)
- *M*
UnitTests/GitUITests/UserControls/ToolStripClasses/CommitIconProviderTests.cs
<https://github.com/gitextensions/gitextensions/pull/4654/files#diff-12>
(5)
Patch Links:
- https://github.com/gitextensions/gitextensions/pull/4654.patch
- https://github.com/gitextensions/gitextensions/pull/4654.diff
—
You are receiving this because you are subscribed to this thread.
Reply to this email directly, view it on GitHub
<#4654>, or mute the
thread
<https://github.com/notifications/unsubscribe-auth/ADdhsbArzJ9JLDFhCNX4QFCEsrH8Yd1Rks5tfV2DgaJpZM4Su7G4>
.
|
Codecov Report
@@ Coverage Diff @@
## master #4654 +/- ##
=======================================
Coverage 26.68% 26.68%
=======================================
Files 501 501
Lines 40752 40752
Branches 5961 5963 +2
=======================================
Hits 10873 10873
Misses 29379 29379
Partials 500 500
Continue to review full report at Codecov.
|
You cannot add items to an empty Calling |
Right. I get it. I wasn't thinking of empty. I was focusing on the list
being used to add to later on.
…On Sat, Mar 17, 2018, 3:50 PM Drew Noakes ***@***.***> wrote:
Depends on if you are going to remove or add items. Also there is toarray
on ienumerable.
You cannot add items to an empty IEnumerable<T> or a T[]. That is why
these framework methods return singletons -- they cannot be mutated.
Calling Enumerable.ToArray will allocate you a new array. The point of
this optimisation is to avoid redundant allocations.
—
You are receiving this because you commented.
Reply to this email directly, view it on GitHub
<#4654 (comment)>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/ADdhsUUrl6E-Pqa6tEG27erVDdonQitoks5tfWkIgaJpZM4Su7G4>
.
|
Enumerable.Empty
andArray.Empty
return singleton instances, so reduce overall allocations.Also use
new [] { ... }
overnew List<T> { ... }
in a few places, for lesser allocations. The latter allocates an over-sized array (capacity 16) as well as the overhead ofList<T>
.In a few places I substitute in
IReadOnlyList<T>
. I feel like GE could use this interface more broadly, though understand the interface itself is newer than much of the codebase. I will use it more in future.What did I do to test the code and ensure quality: