You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
do not pass around pointers to slices and maps (#174)
### TL;DR
Refactored BlockData handling to use value types instead of pointers for slices, improving code clarity and reducing unnecessary pointer indirection.
### What changed?
This PR changes the signature of several functions across the codebase to use value types for slices instead of pointers to slices. Specifically:
- Changed `*[]common.BlockData` to `[]common.BlockData` in function parameters and return types
- Changed `*[]common.Block`, `*[]common.Transaction`, `*[]common.Log`, and `*[]common.Trace` to their value counterparts
- Updated all related function calls and implementations to match the new signatures
- Simplified nil checks by using `len()` directly on slices instead of checking for nil pointers first
- Updated mock implementations to reflect these changes
### How to test?
- Run the existing test suite to ensure all functionality works as expected
- Verify that the committer and reorg handler components function correctly with the new type signatures
- Check that storage operations (insert, get, delete) work properly with the refactored types
### Why make this change?
Using pointers to slices was unnecessary and added complexity to the codebase. This change:
1. Improves code readability by removing a layer of indirection
2. Makes the code more idiomatic Go by using value types for slices
3. Simplifies nil checks and length checks on collections
4. Reduces the risk of nil pointer dereferences
5. Makes the API more consistent and easier to understand
The change is purely refactoring and doesn't alter any business logic or functionality.
returnnil, fmt.Errorf("error fetching blocks to commit: %v", err)
119
119
}
120
-
ifblocksData==nil||len(*blocksData) ==0 {
120
+
iflen(blocksData) ==0 {
121
121
log.Warn().Msgf("Committer didn't find the following range in staging: %v - %v", blocksToCommit[0].Int64(), blocksToCommit[len(blocksToCommit)-1].Int64())
0 commit comments