diff --git a/reader/CMakeLists.txt b/reader/CMakeLists.txt index 622cc09..94cba99 100644 --- a/reader/CMakeLists.txt +++ b/reader/CMakeLists.txt @@ -14,7 +14,7 @@ add_definitions( add_executable(${PROJECT_NAME} ${SOURCES}) if(UNIX) - set(SPEC_LIB pthread) + set(SPEC_LIB pthread shared_allocator) endif(UNIX) target_link_libraries(${PROJECT_NAME} easy_profiler ${SPEC_LIB}) \ No newline at end of file diff --git a/reader/main.cpp b/reader/main.cpp index 13dcfb1..a65c16d 100644 --- a/reader/main.cpp +++ b/reader/main.cpp @@ -13,22 +13,24 @@ struct BlocksTree { profiler::SerilizedBlock* node; - std::vector children; + std::vector children; BlocksTree* parent; BlocksTree(){ node = nullptr; parent = nullptr; } - BlocksTree(BlocksTree&& that){ - node = that.node; - parent = that.parent; - - children = std::move(that.children); - - that.node = nullptr; - that.parent = nullptr; + BlocksTree(BlocksTree&& that) + { + makeMove(std::forward(that)); } + + BlocksTree& operator=(BlocksTree&& that) + { + makeMove(std::forward(that)); + return *this; + } + ~BlocksTree(){ if (node){ delete node; @@ -37,27 +39,6 @@ struct BlocksTree parent = nullptr; } - BlocksTree(const BlocksTree& rhs) - { - copy(rhs); - } - - BlocksTree& copy(const BlocksTree& rhs) - { - if(this == &rhs) - return *this; - if(rhs.node) - node = new profiler::SerilizedBlock(*rhs.node); - children = rhs.children; - parent = rhs.parent; - return *this; - } - - BlocksTree& operator=(const BlocksTree& rhs) - { - return copy(rhs); - } - bool operator < (const BlocksTree& other) const { if (!node || !other.node){ @@ -65,6 +46,19 @@ struct BlocksTree } return node->block()->getBegin() < other.node->block()->getBegin(); } + +private: + void makeMove(BlocksTree&& that) + { + node = that.node; + parent = that.parent; + + children = std::move(that.children); + + that.node = nullptr; + that.parent = nullptr; + } + }; int main() @@ -80,6 +74,7 @@ int main() thread_blocks_tree_t threaded_trees; int blocks_counter = 0; + auto start = std::chrono::system_clock::now(); while (!inFile.eof()){ uint16_t sz = 0; @@ -106,7 +101,7 @@ int main() BlocksTree& back = root.children.back(); auto t1 = back.node->block()->getEnd(); auto mt0 = tree.node->block()->getBegin(); - if (mt0 < t1)//parent - starts ealier than last ends + if (mt0 < t1)//parent - starts earlier than last ends { auto lower = std::lower_bound(root.children.begin(), root.children.end(), tree); @@ -114,7 +109,6 @@ int main() root.children.erase(lower, root.children.end()); - } root.children.push_back(std::move(tree));