Skip to content

Simplify EquiZip implementation - #902

Closed
viceroypenguin wants to merge 2 commits into
morelinq:masterfrom
viceroypenguin:equizip-implementation
Closed

Simplify EquiZip implementation#902
viceroypenguin wants to merge 2 commits into
morelinq:masterfrom
viceroypenguin:equizip-implementation

Conversation

@viceroypenguin

Copy link
Copy Markdown
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
Copy Markdown
Contributor Author

NB: This may be a v4.0.0 PR?

@codecov

codecov Bot commented Nov 25, 2022

Copy link
Copy Markdown

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
Copy Markdown
Member

Possibly a duplicate of PR #715 by @Orace?

@viceroypenguin

Copy link
Copy Markdown
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

Orace commented Jan 24, 2023

Copy link
Copy Markdown
Contributor

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
Copy Markdown
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