Skip to content

Conversation

@paulirwin
Copy link
Contributor

@paulirwin paulirwin commented Dec 15, 2024

  • You've read the Contributor Guide and Code of Conduct.
  • You've included unit or integration tests for your change, where applicable.
  • You've included inline docs for your change, where applicable.
  • There's an open issue for the PR that you are making. If you'd like to propose a change, please open an issue to discuss the change or find an existing issue.

Removes the covariance and LINQ use from Grouping, breaks GroupingSearch into subclasses

Fixes #1059

Description

See #1059 for rationale. This PR breaks GroupingSearch into three child classes (with some abstract base classes for common configuration properties) so that we can remove the covariance in the interfaces that were added to get this working in the original port. This keeps most of the interfaces but makes them non-generic (and thus, not covariant) for cases where you might need to have them in a common variable or collection. These were also needed for usage in the tests, where the test code randomly switches implementations that otherwise would not have common generic type parameters.

LINQ was removed, and IEnumerable<T> was changed to ICollection<T>/IList<T> to match the original Java code. This should improve performance a little bit by being able to reference Count etc. directly.

@paulirwin paulirwin added the notes:breaking-change Has changes that will break backward compatibility label Dec 15, 2024
@paulirwin paulirwin marked this pull request as ready for review December 15, 2024 23:24
@paulirwin
Copy link
Contributor Author

This old PR has been rebased against latest main. I intend to merge this this coming weekend if there is no further feedback.

Copy link
Contributor

@NightOwl888 NightOwl888 left a comment

Choose a reason for hiding this comment

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

Not a full review, but there are some old comments that I had in a draft that I am posting so they aren't lost.

There was one issue I found on the first pass where it would have made sense to make a method into an extension method so it could expose the underlying type, but I was unable to locate it when I went back to find it again. I am hoping to locate it while this is still a PR.

This is going to take some dedicated time for a full review, though.

This still needs XML doc comments, but this breaks the GroupingSearch
"god class" into three subclasses that implement a common abstract
class. This should allow us to not need covariant interfaces for the
return types.

In order to randomly switch between these classes with incompatible
generic type arguments, the test shows how you can use a delegate to
work around this limitation.
@paulirwin paulirwin requested a review from Copilot September 17, 2025 02:58
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR removes covariance and LINQ usage from the Grouping module to align with the original Java code and improve performance. The main changes involve:

  • Converting generic covariant interfaces to non-generic interfaces with explicit implementations
  • Replacing IEnumerable<T> with ICollection<T>/IList<T> for better performance
  • Adding casting adapter classes to bridge type conversions
  • Breaking GroupingSearch into specialized subclasses

Reviewed Changes

Copilot reviewed 30 out of 31 changed files in this pull request and generated 4 comments.

Show a summary per file
File Description
Support/CastingSetAdapter.cs New adapter class for type-safe casting between set types
Support/CastingListAdapter.cs New adapter class for type-safe casting between list types
Support/CastingEnumeratorAdapter.cs New adapter class for type-safe casting between enumerator types
Support/CastingCollectionAdapter.cs New adapter class for type-safe casting between collection types
Tests Updated test files to use concrete types instead of covariant interfaces
Grouping Refactored interfaces to be non-generic with explicit implementations

Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

notes:breaking-change Has changes that will break backward compatibility

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Refactor Lucene.Net.Grouping to eliminate usage of LINQ, covariant interfaces, and non-generic collection interfaces

2 participants