refactor: using slices.Contains to simplify the code#6234
refactor: using slices.Contains to simplify the code#6234gmalouf merged 1 commit intoalgorand:masterfrom
Conversation
|
Thanks, makes sense. I wonder if there's a tool to find the old code pattern. We've switched to slices.Contains in many places, but missed this one. |
I also search by keywords, and there will be a lot of omissions. But I think I can write such a tool |
I did something with |
|
Oh, the one you found can't be changed. That accountsList is a map, not a slice. My semgrep rule had the same issue. I fixed that, so there are only 5 detected now, instead of 11. |
jannotti
left a comment
There was a problem hiding this comment.
To remove approval, I have to comment. Issue is the map vs slice thing.
Great job. I'll modify the other items you found. |
Everything else has been modified, I will keep an eye on ci. But I feel like these are data/transactions/logic/eval.go
❯❯❱ Users.jj.no-reimplement-slices.Contains
Don't write a loop for that, use slices.Contains instead!
5301┆ for _, assetID := range cx.txn.Txn.ForeignAssets {
5302┆ if assetID == aid {
5303┆ return true
5304┆ }
5305┆ }
⋮┆----------------------------------------
5345┆ for _, appID := range cx.txn.Txn.ForeignApps {
5346┆ if appID == aid {
5347┆ return true
5348┆ }
5349┆ }Since there is no return false operation, it may not be possible to use slice.Contains optimization. |
|
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## master #6234 +/- ##
==========================================
- Coverage 51.83% 51.82% -0.02%
==========================================
Files 643 643
Lines 86382 86355 -27
==========================================
- Hits 44780 44754 -26
+ Misses 38735 38730 -5
- Partials 2867 2871 +4 ☔ View full report in Codecov by Sentry. |
eea4137 to
00e5073
Compare
That makes sense! Modified. Please review again. Thank you! |
|
All CI checks have passed, please review again. |
Signed-off-by: damuzhi0810 <rust@before.tech>
Summary
This is a new function added in the go1.21 standard library, which can make the code more concise and easy to read.
Test Plan