-
Notifications
You must be signed in to change notification settings - Fork 2.3k
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
fix unnecesssary allocation in infile.go #1600
Conversation
Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media? TipsChatThere are 3 ways to chat with CodeRabbit:
Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments. CodeRabbit Commands (invoked as PR comments)
Additionally, you can add CodeRabbit Configration File (
|
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.
Actionable comments posted: 1
Outside diff range and nitpick comments (1)
infile.go (1)
Line range hint
103-103
: Consider simplifying the conditional logic to enhance readability.- if idx == 0 || (idx > 0 && name[idx-1] == '/') + if idx >= 0 && (idx == 0 || name[idx-1] == '/')Tools
golangci-lint
96-96: Function 'handleInFileRequest' is too long (86 > 60) (funlen)
Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Files selected for processing (1)
- infile.go (2 hunks)
Additional context used
golangci-lint
infile.go
96-96: Function 'handleInFileRequest' is too long (86 > 60) (funlen)
103-103:
if idx == 0 || (idx > 0 && name[idx-1] == '/')
has complex nested blocks (complexity: 20) (nestif)
Additional comments not posted (2)
infile.go (2)
149-153
: The changes correctly address the unnecessary allocation by moving thedata
array creation outside the loop and conditionally initializing it based onpacketSize
. Good job on optimizing this!Also applies to: 160-160
Line range hint
160-160
: Handling EOF as a non-error case is appropriate for file read operations.Tools
golangci-lint
96-96: Function 'handleInFileRequest' is too long (86 > 60) (funlen)
@@ -95,7 +95,6 @@ const defaultPacketSize = 16 * 1024 // 16KB is small enough for disk readahead a | |||
|
|||
func (mc *okHandler) handleInFileRequest(name string) (err error) { |
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.
The function is quite lengthy and complex. Consider refactoring into smaller, more focused functions to improve maintainability and testability.
Tools
golangci-lint
96-96: Function 'handleInFileRequest' is too long (86 > 60) (funlen)
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.
LGTM
Description
There is a code
if data == nil
to avoid allocation when sending empty packet inhandleInFileRequest()
.But it didn't work because previous allocation happend inner block as
data := make(...)
.VSCode warns that
if data == nil
is tautology.Checklist