-
Notifications
You must be signed in to change notification settings - Fork 1.2k
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
Replace ArrayList in InputLanguageSource with fixed-size array, reduce allocations #9221
Replace ArrayList in InputLanguageSource with fixed-size array, reduce allocations #9221
Conversation
I will just point out that this value is returned by public API via On the positive side, the ownership is not documented, the public contract is |
You're returning an interface for a reason, to interface with it. That is the contract that was given. Relying on an implementation detail such as this is the same as using reflection on private types in a foreign assembly. Note aside: Don't worry about the |
Why List rather than an array then?
Not quite as all the involved types are public and you were able to do this even in partial trust. In the sense of "relying on implementation detail", sure. As I said I am happy with this one going ahead, I just wouldn't necessarily call it "None" risk.
Never had doubts about that. :) |
Now that is a very good question that I do not have an answer to. @siagupta0202 Would it be too late to change it?
When implemented by a class, this property should return an object that implements the IEnumerable interface, and that supports enumerating a collection of CultureInfo objects, each representing a supported input language. We can refer to the wording, relying on
Fair point. Could have been outlined better from my side :)
Wouldn't believe you if you said you did, haha. |
Ah good idea checking the interface documentation, I missed that. The one for AvailableInputLanguages could certainly use some tightening (since the relevance/existence of the interface is not clear). |
Yeah, agreed. |
@h3xds1nz it's not too late, you can still make the changes. |
@siagupta0202 Thanks, will push it shortly. |
a9530ef
to
c80e4de
Compare
@h3xds1nz Thank you for your contribution. |
@harshit7962 Thanks for including it. |
Description
Replaces
ArrayList
with aCultureInfo[]
of 1 item downcasted toIEnumerable
to improve performance of retrieval and decrease allocations caused by allocating anArrayList
and adding an item into it.Customer Impact
Improved performance, less allocations.
Regression
No.
Testing
Local build, CI.
Risk
As outlined in the discussion with @miloush, this is a change to a public type under the hood. If someone was relying on an implementation detail, that this was an
ArrayList
, it would break. Do note that is nowhere documented this is anArrayList
.Documentation clearly states for InputLanguageList property (nobody should assume otherwise):
When implemented by a class, this property should return an object that implements the IEnumerable interface, and that supports enumerating a collection of CultureInfo objects, each representing a supported input language.
Microsoft Reviewers: Open in CodeFlow