reserve capacity to fast_oss
This commit is contained in:
		@@ -18,7 +18,10 @@ using namespace utils;
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
int main(int argc, char* argv[])
 | 
					int main(int argc, char* argv[])
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
    if(argc || argv) {};
 | 
					
 | 
				
			||||||
 | 
						if(argc || argv) {};
 | 
				
			||||||
 | 
						std::string s;
 | 
				
			||||||
 | 
						cout << "STRING cap: " << format(s.capacity()) << endl;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    auto fsink = std::make_shared<sinks::rotating_file_sink>("log", "txt", 1024*1024*50 , 5, 0);
 | 
					    auto fsink = std::make_shared<sinks::rotating_file_sink>("log", "txt", 1024*1024*50 , 5, 0);
 | 
				
			||||||
	//auto fsink = std::make_shared<sinks::simple_file_sink>("simplelog", "txt");
 | 
						//auto fsink = std::make_shared<sinks::simple_file_sink>("simplelog", "txt");
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -40,6 +40,12 @@ protected:
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
    virtual std::streamsize xsputn(const char_type* s, std::streamsize count) override
 | 
					    virtual std::streamsize xsputn(const char_type* s, std::streamsize count) override
 | 
				
			||||||
    {
 | 
					    {
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
							auto ssize = _str.size();
 | 
				
			||||||
 | 
							auto cap_left = _str.capacity() - ssize;
 | 
				
			||||||
 | 
							if(cap_left < static_cast<std::size_t>(count))
 | 
				
			||||||
 | 
								_str.reserve(ssize + count + 128);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        _str.append(s, static_cast<unsigned int>(count));
 | 
					        _str.append(s, static_cast<unsigned int>(count));
 | 
				
			||||||
        return count;
 | 
					        return count;
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user