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

Simplify EquiZip implementation #902

Closed
wants to merge 2 commits into from
Closed

Simplify EquiZip implementation #902

wants to merge 2 commits into from

Conversation

viceroypenguin
Copy link
Contributor

The various Zip* methods currently share implementation in .ZipImpl(). However, the code is simpler for each one when they are written separately; that is, in this case, the variances are more than the commonality. As such, we should allow each method to be implemented separately.

This PR updates the implementation of EquiZip to be done separately from .ZipImpl().

@viceroypenguin
Copy link
Contributor Author

NB: This may be a v4.0.0 PR?

@codecov
Copy link

codecov bot commented Nov 25, 2022

Codecov Report

Merging #902 (5ff2ad4) into master (60ec000) will increase coverage by 0.02%.
The diff coverage is 100.00%.

@@            Coverage Diff             @@
##           master     #902      +/-   ##
==========================================
+ Coverage   92.41%   92.43%   +0.02%     
==========================================
  Files         112      112              
  Lines        3426     3425       -1     
  Branches     1017     1019       +2     
==========================================
  Hits         3166     3166              
+ Misses        199      198       -1     
  Partials       61       61              
Impacted Files Coverage Δ
MoreLinq/EquiZip.cs 100.00% <100.00%> (+4.08%) ⬆️
MoreLinq/ZipImpl.cs 97.77% <0.00%> (-2.23%) ⬇️

📣 We’re building smart automated test selection to slash your CI/CD build times. Learn more

@atifaziz
Copy link
Member

Possibly a duplicate of PR #715 by @Orace?

@viceroypenguin
Copy link
Contributor Author

Duplicate in the sense that both separate the implementations of the three zip functions, yes. However, #715 uses T4 to generate separate implementations of each method for argument count 2-4. Also, #715 and #902 have very different implementations. IMO #902 is simpler, because the control flow is more linear, rather than 4-way branch with multiple exit points.

@Orace
Copy link
Contributor

Orace commented Jan 24, 2023

Some thoughts about this:

  • The used pattern probably wastes resources. It's implemented for 4 sources, and for other cases, it uses dummy sources and discards values with a lambda (resulting to memory allocation that can be avoided):

    return EquiZipImpl(first, second, Enumerable.Repeat(default(object?), int.MaxValue), Enumerable.Repeat(default(object?), int.MaxValue), (a, b, _, _) => resultSelector(a, b), 2);

    It will not scale well if we want to add overloads with more sources.

  • The control flow of Zip refactoring #715 can be simplified a little bit to match Simplify EquiZip implementation #902 that offers more complete exception messages.

@viceroypenguin
Copy link
Contributor Author

@Orace Here's a copy of the code gen for a simpler control flow if you want to steal it.

Closing this PR in favor of an updated #715.

@viceroypenguin viceroypenguin deleted the equizip-implementation branch January 27, 2023 12:19
@viceroypenguin viceroypenguin deleted the equizip-implementation branch January 27, 2023 12:19
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