Skip to content

Conversation

@ties
Copy link
Contributor

@ties ties commented Aug 16, 2025

I looked at the usage of BytesMut and realised that one case could be a bit cleaner:

-    let mut buffer = BytesMut::with_capacity(common_header.length as usize);
-    buffer.resize(common_header.length as usize, 0);
+    let mut buffer = BytesMut::zeroed(common_header.length as usize);

I ended up bikeshedding some more cases. I think that in general most usage of Bytes can be replaced by Buf which would allow a reference to a u8 slice to be passed in.

@digizeph digizeph requested a review from Copilot August 16, 2025 21:03
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR optimizes BufMut usage throughout the codebase by replacing inefficient buffer allocation patterns with more direct alternatives and improving capacity management.

  • Replaces BytesMut::with_capacity() + resize() with BytesMut::zeroed() for cleaner initialization
  • Substitutes BytesMut with direct slice references where appropriate to avoid unnecessary allocations
  • Adds proper capacity allocation for buffer operations to improve performance

Reviewed Changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated 1 comment.

File Description
src/parser/mrt/mrt_record.rs Optimizes buffer initialization and adds capacity pre-allocation
src/parser/mrt/mrt_header.rs Replaces BytesMut with direct slice references for parsing
src/models/network/asn.rs Improves PartialOrd implementation and adds capacity pre-allocation
.claude/settings.local.json Adds Claude configuration file for development permissions

Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.

@digizeph digizeph merged commit 287f60a into bgpkit:main Aug 16, 2025
2 of 3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants