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.
I don't anticipate that this will affect the performance at all, but it will remove a lot of conditionals that appear redundant.
In Go,
append(x, someElement)
, wherex
is anil
slice, will create a new slice to containsomeElement
, it won't explode. Similarly, accessing a non-existent element of amap
will return the zero value, which will benil
for a slice like[]int
, it won't explode either. Iterating or checking the length of anil
slice will work fine too, it'll just be the equivalent of doing the same operations to an empty slice.I haven't actually tested this code because I didn't feel like setting up the whole environment, but I think it should work.
in my opinion, it's also more idiomatic to construct values once the fields are all known, which you were already doing sometimes, so I added a commit to do that in one other place.