diff options
author | Carlos Martín Nieto <cmn@dwim.me> | 2015-12-15 16:26:26 +0300 |
---|---|---|
committer | Carlos Martín Nieto <cmn@dwim.me> | 2016-03-07 12:53:02 +0300 |
commit | 24c4a8e090c806a4b197ddff3e81cf6384ed1e84 (patch) | |
tree | c251adca31238b0601c1c1e6ad130a7871d81d80 | |
parent | d6282d3b56e09c96df823e4fbadb07c3deb9777b (diff) |
Don't load refspecs eagerly
If the user never asks for the refspecs, we should not spend the time and memory
to load them into managed memory.
-rw-r--r-- | LibGit2Sharp/RefSpecCollection.cs | 14 |
1 files changed, 10 insertions, 4 deletions
diff --git a/LibGit2Sharp/RefSpecCollection.cs b/LibGit2Sharp/RefSpecCollection.cs index 34eb3cb6..46b1c436 100644 --- a/LibGit2Sharp/RefSpecCollection.cs +++ b/LibGit2Sharp/RefSpecCollection.cs @@ -1,4 +1,5 @@ -using System.Collections; +using System; +using System.Collections; using System.Collections.Generic; using System.Diagnostics; using System.Globalization; @@ -14,7 +15,9 @@ namespace LibGit2Sharp [DebuggerDisplay("{DebuggerDisplay,nq}")] public class RefSpecCollection : IEnumerable<RefSpec> { - readonly IList<RefSpec> refspecs; + readonly Remote remote; + readonly RemoteSafeHandle handle; + readonly Lazy<IList<RefSpec>> refspecs; /// <summary> /// Needed for mocking purposes. @@ -26,7 +29,10 @@ namespace LibGit2Sharp { Ensure.ArgumentNotNull(handle, "handle"); - refspecs = RetrieveRefSpecs(remote, handle); + this.remote = remote; + this.handle = handle; + + refspecs = new Lazy<IList<RefSpec>>(() => RetrieveRefSpecs(remote, handle)); } static IList<RefSpec> RetrieveRefSpecs(Remote remote, RemoteSafeHandle remoteHandle) @@ -48,7 +54,7 @@ namespace LibGit2Sharp /// <returns>An <see cref="IEnumerator{T}"/> object that can be used to iterate through the collection.</returns> public virtual IEnumerator<RefSpec> GetEnumerator() { - return refspecs.GetEnumerator(); + return refspecs.Value.GetEnumerator(); } /// <summary> |