Skip to content
This repository was archived by the owner on Dec 14, 2018. It is now read-only.

Modifying ViewDataDictionary and ModelStateDictionary to copy on write instead of eagerly copying. #973

Closed
wants to merge 3 commits into from

Conversation

pranavkm
Copy link
Contributor

Partial fix for #878

@pranavkm pranavkm changed the title Modifying ViewDataDictionary and RouteValueDictionary to copy on write instead of eagerly copying. Modifying ViewDataDictionary and ModelStateDictionary to copy on write instead of eagerly copying. Aug 12, 2014
return ReadDictionary.Contains(item);
}

public virtual void CopyTo(KeyValuePair<TKey, TValue>[] array, int arrayIndex)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[NotNull]

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This might not work if TKey is a value type though. I'd rather have the calling code do the NotNull checks for us

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We could add a a type constraint to TKey since the 2 consumers we have now have string keys, but seeing that it's not public API, seems crummy. Thoughts?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

its not an error to check a struct for nullity it's a warning. that concern would come up elsewhere when implementing [NotNull]

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You'd still fail with warning as errors. Regardless, @dougbu suggested changing this to be an IDictionary(string, TValue) since either consumer is of that type. That should avoid this issue

@yishaigalatzer
Copy link
Contributor

other than the comment on removing the copying of the modelstate dictionary, I'm fine with most of the rest. Let's talk about that one in person.

Other than that :shipit: when the other folks say :shipit:

@pranavkm
Copy link
Contributor Author

Updated PR

_data.Add(entry.Key, entry.Value);
}

TemplateInfo = new TemplateInfo(source.TemplateInfo);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

pls find a way to avoid constructing 2 new TemplateInfo instances when this constructor is called. TemplateInfo will already be non-null when this line is reached.

@dougbu
Copy link
Member

dougbu commented Aug 14, 2014

⌚ waiting, primarily for tests that ModelStateDictionary and ViewDataDictionary have copy-on-write semantics. Currently are primarily testing internal details -- the CopyOnWriteDictionary itself.

@pranavkm
Copy link
Contributor Author

Updated

@@ -13,7 +13,7 @@ namespace Microsoft.AspNet.Mvc
{
public class ViewDataDictionary : IDictionary<string, object>
{
private readonly IDictionary<string, object> _data;
internal readonly IDictionary<string, object> _data;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ick. Just internal but ick all the same. How about an internal property exposing _data's Type? Mark that with // for testing only).
Same for the newly-internal field in ModelStateDictionary.

@dougbu
Copy link
Member

dougbu commented Aug 15, 2014

🚢 it if @rynowak agrees his comments have been addressed and once you do something about those internal fields.

@rynowak
Copy link
Member

rynowak commented Aug 15, 2014

:shipit: once internal fields are gone

@pranavkm pranavkm closed this Aug 15, 2014
@pranavkm pranavkm deleted the CopyOnWriteDictionary branch August 15, 2014 01:21
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants