From fd0b0a2db8987c062d4727543b6663dae7ff28fd Mon Sep 17 00:00:00 2001 From: ChunelFeng Date: Sat, 31 Aug 2024 00:09:30 +0800 Subject: [PATCH] [perf] optimize template function return value. --- src/GraphCtrl/GraphPipeline/GPipeline.h | 30 +++++++++++------------ src/GraphCtrl/GraphPipeline/GPipeline.inl | 26 ++++++++++---------- test/Performance/test-performance-04.cpp | 3 ++- 3 files changed, 30 insertions(+), 29 deletions(-) diff --git a/src/GraphCtrl/GraphPipeline/GPipeline.h b/src/GraphCtrl/GraphPipeline/GPipeline.h index c0ba7e2..894c61e 100644 --- a/src/GraphCtrl/GraphPipeline/GPipeline.h +++ b/src/GraphCtrl/GraphPipeline/GPipeline.h @@ -99,7 +99,7 @@ class GPipeline : public GPipelineObject, */ template::value, int> = 0> - GNodePtr createGNode(const GNodeInfo &info, Args&&... args); + TNode* createGNode(const GNodeInfo &info, Args&&... args); /** * 根据传入的信息,创建node节点 @@ -111,12 +111,12 @@ class GPipeline : public GPipelineObject, * @param args * @return */ - template::value, int> = 0> - GNodePtr createGNode(const GElementPtrSet& dependence = std::initializer_list(), - const std::string& name = CGRAPH_EMPTY, - CSize loop = CGRAPH_DEFAULT_LOOP_TIMES, - Args&&... args); + template::value, int> = 0> + TNode* createGNode(const GElementPtrSet& dependence = std::initializer_list(), + const std::string& name = CGRAPH_EMPTY, + CSize loop = CGRAPH_DEFAULT_LOOP_TIMES, + Args&&... args); /** * 根据传入的信息,创建Group信息 @@ -127,12 +127,12 @@ class GPipeline : public GPipelineObject, * @param loop * @return */ - template::value, int> = 0> - GGroupPtr createGGroup(const GElementPtrArr &elements, - const GElementPtrSet &dependElements = std::initializer_list(), - const std::string &name = CGRAPH_EMPTY, - CSize loop = CGRAPH_DEFAULT_LOOP_TIMES); + template::value, int> = 0> + TGroup* createGGroup(const GElementPtrArr &elements, + const GElementPtrSet &dependElements = std::initializer_list(), + const std::string &name = CGRAPH_EMPTY, + CSize loop = CGRAPH_DEFAULT_LOOP_TIMES); /** * 在图中注册一个 GElement信息 @@ -177,8 +177,8 @@ class GPipeline : public GPipelineObject, template::value, int> = 0> TNode* registerGNode(const GElementPtrSet &dependElements = std::initializer_list(), - const std::string &name = CGRAPH_EMPTY, - CSize loop = CGRAPH_DEFAULT_LOOP_TIMES); + const std::string &name = CGRAPH_EMPTY, + CSize loop = CGRAPH_DEFAULT_LOOP_TIMES); /** * 注册一个 node diff --git a/src/GraphCtrl/GraphPipeline/GPipeline.inl b/src/GraphCtrl/GraphPipeline/GPipeline.inl index f069a86..2b2d4a6 100644 --- a/src/GraphCtrl/GraphPipeline/GPipeline.inl +++ b/src/GraphCtrl/GraphPipeline/GPipeline.inl @@ -116,11 +116,11 @@ CStatus GPipeline::registerGElement(GCoordinatorPPtr coordinatorRef, template::value, int>> -GNodePtr GPipeline::createGNode(const GNodeInfo &info, Args&&... args) { +TNode* GPipeline::createGNode(const GNodeInfo &info, Args&&... args) { CGRAPH_FUNCTION_BEGIN CGRAPH_ASSERT_INIT_THROW_ERROR(false) - GNodePtr node = new(std::nothrow) TNode(std::forward(args)...); + auto* node = new(std::nothrow) TNode(std::forward(args)...); CGRAPH_ASSERT_NOT_NULL_THROW_ERROR(node) status = node->addElementInfo(info.dependence_, info.name_, info.loop_); CGRAPH_THROW_EXCEPTION_BY_STATUS(status) @@ -130,21 +130,21 @@ GNodePtr GPipeline::createGNode(const GNodeInfo &info, Args&&... args) { } -template::value, int>> -GNodePtr GPipeline::createGNode(const GElementPtrSet& dependence, const std::string& name, +template::value, int>> +TNode* GPipeline::createGNode(const GElementPtrSet& dependence, const std::string& name, CSize loop, Args&&... args) { const GNodeInfo& info = GNodeInfo(dependence, name, loop); - return createGNode(info, std::forward(args)...); + return createGNode(info, std::forward(args)...); } -template::value, int>> -GGroupPtr GPipeline::createGGroup(const GElementPtrArr &elements, - const GElementPtrSet &dependElements, - const std::string &name, - CSize loop) { +template::value, int>> +TGroup* GPipeline::createGGroup(const GElementPtrArr &elements, + const GElementPtrSet &dependElements, + const std::string &name, + CSize loop) { CGRAPH_FUNCTION_BEGIN CGRAPH_ASSERT_INIT_THROW_ERROR(false) @@ -156,7 +156,7 @@ GGroupPtr GPipeline::createGGroup(const GElementPtrArr &elements, [](GElementPtr element) { return (nullptr == element); }), "createGGroup dependElements have nullptr.") - GGroupPtr group = CGRAPH_SAFE_MALLOC_COBJECT(T) + auto* group = CGRAPH_SAFE_MALLOC_COBJECT(TGroup) for (GElementPtr element : elements) { status += group->addElement(element); element->belong_ = group; // 从属于这个group的信息 diff --git a/test/Performance/test-performance-04.cpp b/test/Performance/test-performance-04.cpp index ba7cb83..12e0e17 100644 --- a/test/Performance/test-performance-04.cpp +++ b/test/Performance/test-performance-04.cpp @@ -30,7 +30,8 @@ void test_performance_04() { GElementPtrSet beforeLayer {}; for (int i = 0; i < layer; i++) { for (int j = 0; j < nodePerLayer; j++) { - auto* ptr = pipeline->registerGNode(beforeLayer); + GElementPtr ptr = nullptr; + pipeline->registerGElement(&ptr, beforeLayer); curLayer.insert(ptr); }