@@ -59,30 +59,22 @@ void AsyncSink::onLogFrontEnd(const LogContent *content)
59
59
60
60
void AsyncSink::onLogBackEndReadPipe (const void *data_ptr, size_t data_size)
61
61
{
62
- constexpr auto LogContentSize = sizeof (LogContent);
63
- const char *p = reinterpret_cast <const char *>(data_ptr);
64
-
65
- buffer_.reserve (buffer_.size () + data_size);
66
- std::back_insert_iterator<std::vector<char >> back_insert_iter (buffer_);
67
- std::copy (p, p + data_size, back_insert_iter);
62
+ buffer_.append (data_ptr, data_size);
68
63
69
64
bool is_need_flush = false ;
70
- while (buffer_.size () >= LogContentSize ) {
71
- auto content = reinterpret_cast <LogContent*>(buffer_.data ());
72
- auto frame_size = LogContentSize + content->text_len ;
73
- if (frame_size > buffer_.size ()) // ! 总结长度不够
65
+ while (buffer_.readableSize () >= sizeof (LogContent) ) {
66
+ auto content = reinterpret_cast <LogContent*>(buffer_.readableBegin ());
67
+ auto frame_size = sizeof (LogContent) + content->text_len ;
68
+ if (frame_size > buffer_.readableSize ()) // ! 总结长度不够
74
69
break ;
75
70
content->text_ptr = reinterpret_cast <const char *>(content + 1 );
76
71
onLogBackEnd (content);
77
72
is_need_flush = true ;
78
- buffer_.erase (buffer_. begin (), (buffer_. begin () + frame_size) );
73
+ buffer_.hasRead ( frame_size);
79
74
}
80
75
81
- if (is_need_flush) {
76
+ if (is_need_flush)
82
77
flushLog ();
83
- if (buffer_.capacity () > 1024 )
84
- buffer_.shrink_to_fit ();
85
- }
86
78
}
87
79
88
80
void AsyncSink::onLogBackEnd (const LogContent *content)
0 commit comments