refactor: 使用 std::copy 替代 memcpy/memmove#15
Merged
Conversation
- 问题 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() 访问底层数据
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
优化 memcpy 使用
背景
既然 buffer 已经改用 std::vector 管理,部分 memcpy 可以替换为更 C++ 风格的 std::copy。
修改内容
替换为 std::copy
保留 memcpy
新增依赖
代码统计
测试结果
All tests passed (110 assertions in 40 test cases)