Skip to content
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

Remove unnecessary List<T> instantiation #2588

Merged
merged 2 commits into from
Oct 5, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 1 addition & 5 deletions src/Build/Evaluation/Evaluator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -837,12 +837,8 @@ private IDictionary<string, object> Evaluate(ILoggingService loggingService, Bui
if (lazyEvaluator != null)
{
// Tell the lazy evaluator to compute the items and add them to _data
IList<LazyItemEvaluator<P, I, M, D>.ItemData> items = lazyEvaluator.GetAllItems();
// Don't box via IEnumerator and foreach; cache count so not to evaluate via interface each iteration
var itemsCount = items.Count;
for (var i = 0; i < itemsCount; i++)
foreach (var itemData in lazyEvaluator.GetAllItemsDeferred())
{
var itemData = items[i];
if (itemData.ConditionResult)
{
_data.AddItem(itemData.Item);
Expand Down
9 changes: 3 additions & 6 deletions src/Build/Evaluation/LazyItemEvaluator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -401,13 +401,10 @@ private LazyItemList GetItemList(string itemType)
return ret;
}

public IList<ItemData> GetAllItems()
public IEnumerable<ItemData> GetAllItemsDeferred()
{
var ret = _itemLists.Values.SelectMany(itemList => itemList.GetItems(ImmutableHashSet<string>.Empty))
.OrderBy(itemData => itemData.ElementOrder)
.ToList();

return ret;
return _itemLists.Values.SelectMany(itemList => itemList.GetItems(ImmutableHashSet<string>.Empty))
.OrderBy(itemData => itemData.ElementOrder);
}

public void ProcessItemElement(string rootDirectory, ProjectItemElement itemElement, bool conditionResult)
Expand Down