-
Notifications
You must be signed in to change notification settings - Fork 6
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
Test-XliffTranslations: don't append items to existing arrays #18
Comments
The same appears to apply to the return value of
Instead of combining the two existing arrays into a newly allocated array that you subsequently return, please consider returning the arrays separately, one after the other. To illustrate the difference, here's another simplified example: |
Thanks for your suggestion. I will look into it when I have the time. If you have ideas of which changes to make, then feel free to make a PR as well. :) |
In order to use the logic from my first example above, you'd probably have to loop through the translation units twice - once to capture missing entries, and once for capturing entries with problems. Looping twice, of course, comes at a certain performance cost as well, so in this case, we may be better off collecting entries in a collection of a type that does not require reallocation when adding items. My personal preference, for type safety reasons, would be to use a generic List. When a List is written to the output stream, it is automatically unraveled, as you can read here: https://stackoverflow.com/questions/38257354/preserving-powershell-function-return-type. This means that the output type (i.c. the XML node that represents the translation unit) will remain the same as before. |
Shipped in version 1.5.0.0 |
In
Test-XliffTranslations
, you append (potentially numerous) items to the$missingTranslationUnits
and$needWorkTranslationUnits
arrays. In PowerShell (.NET), this is an expensive operation (increasingly so for larger arrays) that can easily be avoided by capturing the items emitted (i.c. by the ForEach-Object command), then storing them in an array all at once.Please consider the performance difference in the (admittedly simple) example below.
The text was updated successfully, but these errors were encountered: