]> git.tdb.fi Git - libs/gl.git/commitdiff
Add push_back_nocopy to NodeContainer for clarity
authorMikko Rasa <tdb@tdb.fi>
Tue, 16 Mar 2021 21:51:21 +0000 (23:51 +0200)
committerMikko Rasa <tdb@tdb.fi>
Tue, 16 Mar 2021 21:51:21 +0000 (23:51 +0200)
It's not immediately obvious that pushing null and then assigning avoids
cloning the node.

source/glsl/generate.cpp
source/glsl/optimize.cpp
source/glsl/syntax.h

index 42b24a9caa949655c6f2a475187aa573d4376447..563609918ae216f28178dca421be4c627175f1b5 100644 (file)
@@ -579,8 +579,7 @@ void ExpressionResolver::convert_to(RefPtr<Expression> &expr, BasicTypeDeclarati
        RefPtr<FunctionCall> call = new FunctionCall;
        call->name = type.name;
        call->constructor = true;
-       call->arguments.push_back(0);
-       call->arguments.back() = expr;
+       call->arguments.push_back_nocopy(expr);
        call->type = &type;
        expr = call;
 }
index d57002552540c6c375cb7446f8465a9538a0a42d..b7a722f42c96c6cc718de3b964697ac9416822bb 100644 (file)
@@ -102,8 +102,7 @@ const string &InlineContentInjector::apply(Stage &stage, FunctionDeclaration &ta
                SetForScope<Pass> set_pass(pass, RENAME);
                var->visit(*this);
 
-               staging_block.body.push_back(0);
-               staging_block.body.back() = var;
+               staging_block.body.push_back_nocopy(var);
                params.push_back(var);
        }
 
@@ -117,8 +116,7 @@ const string &InlineContentInjector::apply(Stage &stage, FunctionDeclaration &ta
                SetForScope<Pass> set_pass(pass, RENAME);
                r_inlined_statement->visit(*this);
 
-               staging_block.body.push_back(0);
-               staging_block.body.back() = r_inlined_statement;
+               staging_block.body.push_back_nocopy(r_inlined_statement);
        }
 
        /* Now collect names from the staging block.  Local variables that would
index 6129421133b0d02ccb416758cf105758a956b01d..9bc3c5a872e865ea9f6506bfcc4d1ba04524144e 100644 (file)
@@ -96,6 +96,9 @@ class NodeContainer: public C
 public:
        NodeContainer() { }
        NodeContainer(const NodeContainer &);
+
+       void push_back_nocopy(const typename C::value_type &v)
+       { C::push_back(0); C::back() = v; }
 };
 
 template<typename T>