-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Allow optional reuse of existing immutable collections when constructing a ProjectInstance. #9374
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
Merged
JanKrivanek
merged 4 commits into
dotnet:main
from
sgreenmsft:dev/sgreen/useImmutableCacheData
Jan 4, 2024
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
d2991da
Modifications to allow use of existing immutable collections when con…
sgreenmsft e499c19
Merge branch 'main' into dev/sgreen/useImmutableCacheData
sgreenmsft d8c6717
Updates as per PR feedback.
sgreenmsft b46cff2
Merge branch 'main' into dev/sgreen/useImmutableCacheData
sgreenmsft File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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
This file contains hidden or 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
This file contains hidden or 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,31 @@ | ||
| // Licensed to the .NET Foundation under one or more agreements. | ||
| // The .NET Foundation licenses this file to you under the MIT license. | ||
|
|
||
| using System; | ||
| using System.Collections.Generic; | ||
|
|
||
| namespace Microsoft.Build.Collections | ||
| { | ||
| /// <summary> | ||
| /// Represents an <see cref="IDictionary{String, TValue}"/> that supports use of an | ||
| /// <see cref="IConstrainedEqualityComparer{T}"/>. | ||
| /// </summary> | ||
| /// <typeparam name="TValue">The type of the values in the dictionary. The key is assumed | ||
| /// to always be <see cref="String"/>.</typeparam> | ||
| internal interface IConstrainableDictionary<TValue> : IDictionary<string, TValue> | ||
| { | ||
| /// <summary> | ||
| /// Get the value with the specified key or null if it is not present. | ||
| /// The key used for lookup is the substring of <paramref name="keyString"/> | ||
| /// starting at <paramref name="startIndex"/> and ending at <paramref name="endIndex"/> | ||
| /// (e.g. if the key is just the first character in <paramref name="keyString"/>, then | ||
| /// the value for <paramref name="startIndex"/> should be 0 and the value for | ||
| /// <paramref name="endIndex"/> should also be 0.) | ||
| /// </summary> | ||
| /// <param name="keyString">A string that contains the key of the item to retrieve.</param> | ||
| /// <param name="startIndex">The start index of the substring of <paramref name="keyString"/> that contains the key.</param> | ||
| /// <param name="endIndex">The end index of the substring of <paramref name="keyString"/> that contains the key.</param> | ||
| /// <returns>If it's found, the item whose key matches the calculated substring. Null otherwise.</returns> | ||
| TValue? Get(string keyString, int startIndex, int endIndex); | ||
| } | ||
| } |
This file contains hidden or 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,134 @@ | ||
| // Licensed to the .NET Foundation under one or more agreements. | ||
| // The .NET Foundation licenses this file to you under the MIT license. | ||
|
|
||
| using System; | ||
| using System.Collections; | ||
| using System.Collections.Generic; | ||
| using System.Linq; | ||
| using System.Text; | ||
| using System.Threading.Tasks; | ||
| using Microsoft.Build.Evaluation; | ||
| using Microsoft.Build.Shared; | ||
|
|
||
| namespace Microsoft.Build.Collections | ||
| { | ||
| internal interface IItemDictionary<T> : IEnumerable<T>, IItemProvider<T> | ||
| where T : class, IKeyed, IItem | ||
| { | ||
| /// <summary> | ||
| /// Number of items in total, for debugging purposes. | ||
| /// </summary> | ||
| int Count { get; } | ||
|
|
||
| /// <summary> | ||
| /// Get the item types that have at least one item in this collection. | ||
| /// </summary> | ||
| /// <remarks> | ||
| /// KeyCollection<K> is already a read only collection, so no protection | ||
| /// is necessary. | ||
| /// </remarks> | ||
| ICollection<string> ItemTypes { get; } | ||
|
|
||
| /// <summary> | ||
| /// Returns the item list for a particular item type, | ||
| /// creating and adding a new item list if necessary. | ||
| /// Does not throw if there are no items of this type. | ||
| /// This is a read-only list. | ||
| /// If the result is not empty it is a live list. | ||
| /// Use AddItem or RemoveItem to modify items in this project. | ||
| /// Using the return value from this in a multithreaded situation is unsafe. | ||
| /// </summary> | ||
| ICollection<T> this[string itemType] { get; } | ||
|
|
||
| /// <summary> | ||
| /// Empty the collection. | ||
| /// </summary> | ||
| void Clear(); | ||
|
|
||
| /// <summary> | ||
| /// Returns an enumerable which copies the underlying data on read. | ||
| /// </summary> | ||
| IEnumerable<TResult> GetCopyOnReadEnumerable<TResult>(Func<T, TResult> selector); | ||
|
|
||
| /// <summary> | ||
| /// Enumerates item lists per each item type under the lock. | ||
| /// </summary> | ||
| /// <param name="itemTypeCallback"> | ||
| /// A delegate that accepts the item type string and a list of items of that type. | ||
| /// Will be called for each item type in the list. | ||
| /// </param> | ||
| void EnumerateItemsPerType(Action<string, IEnumerable<T>> itemTypeCallback); | ||
|
|
||
| /// <summary> | ||
| /// Whether the provided item is in this table or not. | ||
| /// </summary> | ||
| bool Contains(T projectItem); | ||
|
|
||
| /// <summary> | ||
| /// Add a new item to the collection, at the | ||
| /// end of the list of other items with its key. | ||
| /// </summary> | ||
| void Add(T projectItem); | ||
|
|
||
| /// <summary> | ||
| /// Adds each new item to the collection, at the | ||
| /// end of the list of other items with the same key. | ||
| /// </summary> | ||
| void AddRange(IEnumerable<T> projectItems); | ||
|
|
||
| /// <summary> | ||
| /// Removes an item, if it is in the collection. | ||
| /// Returns true if it was found, otherwise false. | ||
| /// </summary> | ||
| /// <remarks> | ||
| /// If a list is emptied, removes the list from the enclosing collection | ||
| /// so it can be garbage collected. | ||
| /// </remarks> | ||
| bool Remove(T projectItem); | ||
|
|
||
| /// <summary> | ||
| /// Replaces an existing item with a new item. This is necessary to preserve the original ordering semantics of Lookup.GetItems | ||
| /// when items with metadata modifications are being returned. See Dev10 bug 480737. | ||
| /// If the item is not found, does nothing. | ||
| /// </summary> | ||
| /// <param name="existingItem">The item to be replaced.</param> | ||
| /// <param name="newItem">The replacement item.</param> | ||
| void Replace(T existingItem, T newItem); | ||
|
|
||
| /// <summary> | ||
| /// Add the set of items specified to this dictionary. | ||
| /// </summary> | ||
| /// <param name="other">An enumerator over the items to remove.</param> | ||
| void ImportItems(IEnumerable<T> other); | ||
|
|
||
| /// <summary> | ||
| /// Add the set of items specified, all sharing an item type, to this dictionary. | ||
| /// </summary> | ||
| /// <comment> | ||
| /// This is a little faster than ImportItems where all the items have the same item type. | ||
| /// </comment> | ||
| void ImportItemsOfType(string itemType, IEnumerable<T> items); | ||
|
|
||
| /// <summary> | ||
| /// Remove the set of items specified from this dictionary | ||
| /// </summary> | ||
| /// <param name="other">An enumerator over the items to remove.</param> | ||
| void RemoveItems(IEnumerable<T> other); | ||
|
|
||
| /// <summary> | ||
| /// Special method used for batching buckets. | ||
| /// Adds an explicit marker indicating there are no items for the specified item type. | ||
| /// In the general case, this is redundant, but batching buckets use this to indicate that they are | ||
| /// batching over the item type, but their bucket does not contain items of that type. | ||
| /// See <see cref="HasEmptyMarker">HasEmptyMarker</see>. | ||
| /// </summary> | ||
| void AddEmptyMarker(string itemType); | ||
|
|
||
| /// <summary> | ||
| /// Special method used for batching buckets. | ||
| /// Lookup can call this to see whether there was an explicit marker placed indicating that | ||
| /// there are no items of this type. See comment on <see cref="AddEmptyMarker">AddEmptyMarker</see>. | ||
| /// </summary> | ||
| bool HasEmptyMarker(string itemType); | ||
| } | ||
| } | ||
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.