refactor: modernize the code by new features provided by golang stand… #3963
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This pull request introduces several code simplifications and performance enhancements by leveraging Go's built-in utility packages (
maps
,slices
, etc.) and improving iteration logic. The changes primarily focus on replacing manual implementations with standard library functions and refactoring iteration patterns for better readability and maintainability.Code Simplifications Using Standard Libraries:
maps.Copy
in multiple locations, such aspeertask_reuse.go
andpeertask_stream.go
, to simplify the code. [1] [2] [3] [4]slices.Delete
instorage_manager.go
andslices.go
. [1] [2]slices.Contains
inhttp_source_client.go
andsource_client.go
. [1] [2]Iteration Refactoring:
for
loops to usefor range
where applicable, improving readability and reducing off-by-one errors. This change affects various test files (peertask_manager_test.go
,peer_exchange_test.go
, etc.) and production code. [1] [2] [3] [4]Utility Enhancements:
min
function calls to replace manual comparisons for calculating minimum values, improving code clarity in files likepeertask_stream_resume_test.go
andpiece_manager.go
. [1] [2] [3]Imports Optimization:
maps
andslices
in relevant files to support the new utility functions. [1] [2] [3]These changes collectively improve the maintainability, readability, and performance of the codebase by leveraging modern Go language features and best practices.
Description
Related Issue
Motivation and Context
Screenshots (if appropriate)
Types of changes
Checklist