提交 f448422a 编写于 作者: C chengtbf 提交者: Will Zhang

in stream read memcpy (#773)



Former-commit-id: 652052bb
上级 4452ec45
#include "oneflow/core/persistence/persistent_in_stream_without_local_copy.h"
#include "oneflow/core/job/job_desc.h"
#include <cstring>
namespace oneflow {
......@@ -23,10 +24,15 @@ int32_t PersistentInStreamWithoutLocalCopy::ReadLine(std::string* l) {
int32_t PersistentInStreamWithoutLocalCopy::Read(char* s, size_t n) {
if (IsEof()) { return -1; }
while (n--) {
while (n) {
if (cur_buf_begin_ == cur_buf_end_) { UpdateBuffer(); }
CHECK_NE(cur_buf_begin_, cur_buf_end_);
*s++ = *cur_buf_begin_++;
CHECK_LT(cur_buf_begin_, cur_buf_end_);
int64_t copy_size =
std::min(cur_buf_end_ - cur_buf_begin_, static_cast<int64_t>(n));
std::memcpy(s, cur_buf_begin_, static_cast<size_t>(copy_size));
s += copy_size;
cur_buf_begin_ += copy_size;
n -= copy_size;
}
return 0;
}
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册