Skip to content

Detect changes in json files regarding dictionary types #38

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
merged 2 commits into from
Jan 11, 2016

Conversation

zhengbli
Copy link
Contributor

@zhengbli zhengbli commented Jan 6, 2016

Related to microsoft/TypeScript#5773

This fix enables the script to detect added/removed/overridden property for dictionary types in the spec.

let removedPropNames =
getRemovedItems ItemKind.Property flavor
|> Array.filter (matchInterface dict.Name)
|> Array.map (fun rp -> rp.Name.Value)
Copy link
Member

Choose a reason for hiding this comment

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

I would tack on

|> Set.ofArray

to make the contains check below faster

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Which contains check?

Copy link
Member

Choose a reason for hiding this comment

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

(fun m -> not (Array.contains m.Name removedPropNames)

I would change Array.contains to Set.contains.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

How is Set.contains faster than Array.contains? My impression is the opposite, because at least Set.contains has an implicit conversion from Array to Set.

Copy link
Member

Choose a reason for hiding this comment

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

Set.contains doesn't do any implicit conversions. You'd pay the construction cost once when building removedPropNames by adding |> Set.ofArray.

Generally, Set.contains is O(lg n) or O(1) and Array.contains is O(n), so if removedPropNames is ever long-ish (10-100 or more items probably?) it will be worth it.

However, I can't find any documentation on Array.contains! Where does Array.contains come from? I see that Shared.fs adds Seq.contains x = Seq.exists ((=)x), which is O(n), but I can't find a definition of Array.contains in our own code.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good point. For some reason I was thinking about Seq instead of Set, therefore had the impression that Array.contains is faster. Will update soon.

I believe Array.contains is added in F# 4.0 which was not very well documented.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done.

@sandersn
Copy link
Member

:1+:

zhengbli added a commit that referenced this pull request Jan 11, 2016
Detect changes in json files regarding dictionary types
@zhengbli zhengbli merged commit 388f252 into master Jan 11, 2016
@zhengbli zhengbli deleted the fixDictionaryIssue branch January 26, 2017 00:16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants