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

refactor: move codes from std::bind to lambda expressions #2475

Merged
merged 14 commits into from
Mar 22, 2024
Merged

Conversation

mehah
Copy link
Contributor

@mehah mehah commented Mar 20, 2024

Overview

This pull request addresses the modernization of our codebase by refactoring instances of std::bind to use lambda expressions instead. This change aligns with modern C++ best practices, enhancing code readability, efficiency, and overall maintainability.

Changes Made

  • Refactored std::bind to Lambda Expressions: Wherever std::bind was used, it has been replaced with lambda expressions. This transition not only simplifies the syntax but also leverages the compiler's ability to optimize lambda expressions more effectively.
  • Code Clean-Up and Simplification: Alongside the refactoring, some related code clean-up and simplification were performed, removing unnecessary complexity and improving the code's readability.
  • Performance Considerations: Preliminary tests indicate that these changes maintain or improve the current performance levels, with the potential for slight runtime improvements due to better optimization of lambda expressions.

Rationale

Lambda expressions, introduced in C++11 and enhanced in subsequent standards, offer several advantages over std::bind:

  • Improved Readability: Lambdas allow for writing more concise and straightforward code, making it easier to understand at a glance.
  • Better Performance: Compilers are generally able to optimize lambda expressions more effectively than std::bind constructs, potentially leading to performance gains.
  • Enhanced Flexibility: Lambda expressions provide greater flexibility in capturing local variables and writing inline code, which can reduce the overall complexity of the codebase.

Testing

The refactored code has been thoroughly tested to ensure that all functionalities remain intact and perform as expected. The tests included unit tests, integration tests, and manual testing to cover various use cases and scenarios.

Conclusion

By adopting modern C++ features such as lambda expressions, we continue to improve the quality of our codebase. These changes not only enhance the current state of the project but also lay a stronger foundation for future development. We encourage further testing and feedback from the community to ensure these improvements meet our collective standards for excellence.

We appreciate the contributions and support from the community in this refactoring effort.

Note: addGameTask and addGameTaskTimed have been removed, it makes no sense to use them, as parsePacket, which performs all actions, is already running within an event that was dispatched to the main thread.

@mehah mehah changed the title perf: bind to lambda perf: std::bind to lambda Mar 20, 2024
Copy link
Contributor

@Mirkaanks Mirkaanks left a comment

Choose a reason for hiding this comment

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

To be honest, I don't see much difference in performance in lambda, but it is better than the old functions.

@dudantas dudantas changed the title perf: std::bind to lambda refactor: move codes from std::bind to lambda expressions Mar 22, 2024
@dudantas dudantas merged commit 685e3af into main Mar 22, 2024
34 checks passed
@dudantas dudantas deleted the bind-to-lambda branch March 22, 2024 21:21
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.

4 participants