Skip to content

refactor: 使用 std::vector 管理内存并修复问题#14

Merged
CPythoner merged 1 commit intomasterfrom
fix/remaining-issues
Apr 3, 2026
Merged

refactor: 使用 std::vector 管理内存并修复问题#14
CPythoner merged 1 commit intomasterfrom
fix/remaining-issues

Conversation

@CPythoner
Copy link
Copy Markdown
Owner

修复 Code Review 中发现的问题

本次修复内容

问题 1.2: equals() 方法缺少 const

  • 添加 const 限定符到 equals() 方法声明

问题 2.1: 使用 std::vector 替代 calloc/free

  • 移除裸指针 p_buffer_,改用 std::vector<uint8_t> buffer_
  • 析构函数改为 default(vector 自动管理内存)
  • 移动语义使用 std::move 管理 vector
  • checkSize 使用 vector::resize 替代 realloc

问题 2.3: compact() 使用 memmove

  • 使用 memmove 替代循环逐字节复制,提高效率

代码统计

  • 删除 53 行
  • 新增 27 行
  • 净减少 26 行

测试结果

All tests passed (110 assertions in 40 test cases)

- 问题 1.2: equals() 方法添加 const 限定符
- 问题 2.1: 使用 std::vector<uint8_t> 替代 calloc/free 进行内存管理
- 问题 2.3: compact() 方法使用 memmove 替代循环逐字节复制

主要改动:
- 移除 p_buffer_ 裸指针,改用 buffer_ (std::vector<uint8_t>)
- 析构函数改为 default
- 移动语义使用 std::move 管理 vector
- checkSize 使用 vector::resize 替代 realloc
- getBytes 使用 buffer_.data() 访问底层数据
@CPythoner CPythoner merged commit ef477df into master Apr 3, 2026
6 checks passed
@CPythoner CPythoner deleted the fix/remaining-issues branch April 4, 2026 08:39
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.

1 participant