Skip to content

Conversation

@quokkaKyu
Copy link
Contributor

@quokkaKyu quokkaKyu commented Jul 4, 2024

Hello, when checking whether the value of Collection Types is empty, how about using 'isEmpty' instead of 'count == 0' considering time complexity and readability?
And How about adding the final keyword to classes that do not inherit?

Thanks for reading.

Checklist

  • I've read the Contribution Guidelines
  • My contributions are licensed under the Swift license.
  • I've followed the coding style of the rest of the project.
  • I've added tests covering all new code paths my change adds to the project (if appropriate).
  • I've added benchmarks covering new functionality (if appropriate).
  • I've verified that my change does not break any existing tests or introduce unexplained benchmark regressions.
  • I've updated the documentation if necessary.

@quokkaKyu quokkaKyu requested a review from lorentey as a code owner July 4, 2024 06:44
@quokkaKyu quokkaKyu changed the title Changed 'count == 0' to 'isEmpty'. Changed 'count == 0' to 'isEmpty' and add 'final' keyword to class Jul 4, 2024
Copy link
Member

@lorentey lorentey left a comment

Choose a reason for hiding this comment

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

Thanks for this work! I do not think it is a good idea to start contributing to a project by applying large-scale stylistic changes.

  • Please retarget this PR on the release/1.1 branch. The future branch is for experimentation; it isn't intended to ever ship in any production release.

  • Marking storage classes final is a good idea. Let's do it! The _DequeBuffer change is acceptable, and we should land it. (I expect the compiler infers final in this case anyway, but making it explicit is not going to hurt.)

  • On the other hand, I am not interested in microoptimizing XCTestCase declarations. Please remove the changes that mark those classes final.

  • I do not expect count == 0 vs isEmpty to make any actual difference for the specific types on which we're calling them. Do you have any evidence to the contrary?

  • Please make sure not to break indentation.

#endif

class CombinatoricsTests: CollectionTestCase {
final class CombinatoricsTests: CollectionTestCase {
Copy link
Member

Choose a reason for hiding this comment

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

I'm not interested in microoptimizing XCTestCase classes. Please remove these changes from all test files.

Copy link
Contributor Author

@quokkaKyu quokkaKyu Jul 9, 2024

Choose a reason for hiding this comment

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

Thank you for the reply. i will delete the changes in the test files.

assert(offsets.lowerBound >= 0 && offsets.upperBound <= count)
let lower = slot(forOffset: offsets.lowerBound)
let upper = slot(forOffset: offsets.upperBound)
if offsets.count == 0 || lower < upper {
Copy link
Member

Choose a reason for hiding this comment

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

I don't expect Range.count == 0 to produce less efficient code than Range.isEmpty -- do you have proof that it matters?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

No, I may be mistaken. Since it is a RandomAccessCollection type, I don’t think there will be any difference.

let lower = slot(forOffset: offsets.lowerBound)
let upper = slot(forOffset: offsets.upperBound)
if offsets.count == 0 || lower < upper {
return .init(start: ptr(at: lower), count: offsets.count)
Copy link
Member

Choose a reason for hiding this comment

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

Please do not break indentation.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

yes, i won't break the indentation.

count: 1
) { children, items in
assert(items.count == 1 && children.count == 0)
assert(items.count == 1 && children.isEmpty)
Copy link
Member

Choose a reason for hiding this comment

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

children is of type UnsafeMutableBufferPointer. Do you have evidence that this change has a meaningful impact?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

No, I may be mistaken. Since it is a RandomAccessCollection type, I don’t think there will be any difference.

@lorentey
Copy link
Member

lorentey commented Aug 1, 2024

Closing; the _DequeBuffer change has landed with #403, and the rest of these changes appear unnecessary. Thanks for this work anyway! If I missed something, please push and reopen as needed.

@lorentey lorentey closed this Aug 1, 2024
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.

2 participants