-
Notifications
You must be signed in to change notification settings - Fork 471
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
Chore: Use exp/slices and exp/maps to simplify some code #5479
Merged
Merged
Changes from all commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
5c1bedc
Use exp/slices and exp/maps to simplify some code
jannotti 9192bc4
Use maps.Clear
jannotti 43ffe44
dead code
jannotti 6e40ea0
another clone
jannotti 25ceeb3
slices.Index and deadcode
jannotti ef29274
maps.Equal
jannotti 0e20408
Never use strings.Compare
jannotti b2d40d9
The easier CR fixes from jasonpaulos.
jannotti 34ee175
revereting, since it might not be as memory efficient
jannotti 49b4704
new -> newMap
jannotti f067653
Dead code as far as the eye can see.
jannotti 025be8d
remove a couple one-liners
jannotti c4244a0
Merge remote-tracking branch 'upstream/master' into generic-stuff
jannotti File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -21,6 +21,7 @@ import ( | |
"fmt" | ||
|
||
"github.com/algorand/go-algorand/config" | ||
"golang.org/x/exp/maps" | ||
) | ||
|
||
// DeltaAction is an enum of actions that may be performed when applying a | ||
|
@@ -77,24 +78,7 @@ type StateDelta map[string]ValueDelta | |
// equality because an empty map will encode/decode as nil. So if our generated | ||
// map is empty but not nil, we want to equal a decoded nil off the wire. | ||
func (sd StateDelta) Equal(o StateDelta) bool { | ||
// Lengths should be the same | ||
if len(sd) != len(o) { | ||
return false | ||
} | ||
// All keys and deltas should be the same | ||
for k, v := range sd { | ||
// Other StateDelta must contain key | ||
ov, ok := o[k] | ||
if !ok { | ||
return false | ||
} | ||
|
||
// Other StateDelta must have same value for key | ||
if ov != v { | ||
return false | ||
} | ||
} | ||
return true | ||
return maps.Equal(sd, o) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Comment goes into a lot of detail about the |
||
} | ||
|
||
// Valid checks whether the keys and values in a StateDelta conform to the | ||
|
@@ -234,14 +218,7 @@ type TealKeyValue map[string]TealValue | |
// Clone returns a copy of a TealKeyValue that may be modified without | ||
// affecting the original | ||
func (tk TealKeyValue) Clone() TealKeyValue { | ||
if tk == nil { | ||
return nil | ||
} | ||
res := make(TealKeyValue, len(tk)) | ||
for k, v := range tk { | ||
res[k] = v | ||
} | ||
return res | ||
return maps.Clone(tk) | ||
} | ||
|
||
// ToStateSchema calculates the number of each value type in a TealKeyValue and | ||
|
Oops, something went wrong.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not even sure this needs the clone. When called as varargs, the slice is surely unshared.