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

perf(deque): use @deque.iter[2]() for @deque.each[i]() #1357

Merged
merged 2 commits into from
Dec 25, 2024

Conversation

rami3l
Copy link
Contributor

@rami3l rami3l commented Dec 24, 2024

Continuation of #1354.

Summary

Improvements to iteration methods:

  • pub fn each[A](self : T[A], f : (A) -> Unit) -> Unit: Updated the method to use a direct iteration over the collection instead of indexing.
  • pub fn eachi[A](self : T[A], f : (Int, A) -> Unit) -> Unit: Updated the method to use a direct iteration with index over the collection instead of indexing.

@coveralls
Copy link
Collaborator

coveralls commented Dec 24, 2024

Pull Request Test Coverage Report for Build 4306

Details

  • 2 of 2 (100.0%) changed or added relevant lines in 1 file are covered.
  • No unchanged relevant lines lost coverage.
  • Overall coverage decreased (-0.006%) to 81.248%

Totals Coverage Status
Change from base Build 4303: -0.006%
Covered Lines: 4623
Relevant Lines: 5690

💛 - Coveralls

Copy link

peter-jerry-ye-code-review bot commented Dec 24, 2024

‼️ This code review is generated by a bot. Please verify the content before trusting it.

The provided git diff output shows changes to a deque implementation, specifically in the each and eachi functions. Here are three potential issues or improvements that can be observed:

  1. Inconsistent Loop Syntax:

    • The original code uses a traditional for loop with an index (for i = 0; i < self.length(); i = i + 1), while the updated code uses a more idiomatic iterator-based loop (for v in self and for i, v in self).
    • Potential Problem: If the self type does not implement the necessary iterator protocol (e.g., Iterator or IntoIterator), the new syntax will not work. Ensure that T[A] implements the appropriate iterator traits.
  2. Potential Performance Issue:

    • The original code explicitly calls self.length() in each iteration of the loop, which is fine if self.length() is a constant-time operation. However, the new code relies on the iterator protocol, which might be less efficient if the iterator does not optimize for performance.
    • Potential Problem: If the iterator is not optimized, this could lead to a performance regression. Ensure that the iterator implementation is efficient.
  3. Typo in Comment:

    • In the eachi function, the comment mentions idx_sum but does not provide a clear explanation of what idx_sum represents.
    • Potential Problem: This could confuse readers of the code. Consider updating the comment to provide more context or an example of what idx_sum is supposed to represent.

These are the three main observations based on the provided diff.

@bobzhang bobzhang merged commit 3de9e44 into main Dec 25, 2024
13 checks passed
@bobzhang bobzhang deleted the perf/deque-each-i branch December 25, 2024 05:36
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