mirror of
https://github.com/yse/easy_profiler.git
synced 2024-12-28 01:04:41 +08:00
Removed redundant copying of data from std::stringstream to std::ofstream in dumpBlocksToFile()
This commit is contained in:
parent
c0a23866ed
commit
105d8334e1
@ -60,6 +60,11 @@ namespace profiler {
|
||||
m_stream.write((const char*)&_data, sizeof(T));
|
||||
}
|
||||
|
||||
::std::stringstream& stream()
|
||||
{
|
||||
return m_stream;
|
||||
}
|
||||
|
||||
const ::std::stringstream& stream() const
|
||||
{
|
||||
return m_stream;
|
||||
|
@ -1009,11 +1009,22 @@ uint32_t ProfileManager::dumpBlocksToStream(profiler::OStream& _outputStream, bo
|
||||
|
||||
uint32_t ProfileManager::dumpBlocksToFile(const char* _filename)
|
||||
{
|
||||
std::ofstream outputFile(_filename, std::fstream::binary);
|
||||
if (!outputFile.is_open())
|
||||
return 0;
|
||||
|
||||
profiler::OStream outputStream;
|
||||
|
||||
// Replace outputStream buffer to outputFile buffer to avoid redundant copying
|
||||
typedef ::std::basic_iostream<std::stringstream::char_type, std::stringstream::traits_type> stringstream_parent;
|
||||
stringstream_parent& s = outputStream.stream();
|
||||
auto oldbuf = s.rdbuf(outputFile.rdbuf());
|
||||
|
||||
// Write data directly to file
|
||||
const auto blocksNumber = dumpBlocksToStream(outputStream, true);
|
||||
|
||||
std::ofstream of(_filename, std::fstream::binary);
|
||||
of << outputStream.stream().str();
|
||||
// Restore old outputStream buffer to avoid possible second memory free on stringstream destructor
|
||||
s.rdbuf(oldbuf);
|
||||
|
||||
return blocksNumber;
|
||||
}
|
||||
|
@ -372,12 +372,16 @@ extern "C" {
|
||||
|
||||
::std::stringstream str;
|
||||
|
||||
// Replace str buffer to inFile buffer to avoid redundant copying
|
||||
typedef ::std::basic_iostream<::std::stringstream::char_type, ::std::stringstream::traits_type> stringstream_parent;
|
||||
stringstream_parent& s = str;
|
||||
auto oldbuf = s.rdbuf(inFile.rdbuf());
|
||||
|
||||
// Read data from file
|
||||
auto result = fillTreesFromStream(progress, str, serialized_blocks, serialized_descriptors, descriptors, blocks,
|
||||
threaded_trees, total_descriptors_number, gather_statistics, _log);
|
||||
|
||||
// Restore old str buffer to avoid possible second memory free on stringstream destructor
|
||||
s.rdbuf(oldbuf);
|
||||
|
||||
return result;
|
||||
|
Loading…
x
Reference in New Issue
Block a user