]> git.tdb.fi Git - libs/gl.git/commitdiff
Use emplace_back when a new object is being constructed
authorMikko Rasa <tdb@tdb.fi>
Wed, 17 Nov 2021 15:12:19 +0000 (17:12 +0200)
committerMikko Rasa <tdb@tdb.fi>
Wed, 17 Nov 2021 15:12:19 +0000 (17:12 +0200)
13 files changed:
source/animation/animation.cpp
source/animation/animationplayer.cpp
source/animation/armature.cpp
source/backends/opengl/program_backend.cpp
source/builders/sequencetemplate.cpp
source/core/program.cpp
source/glsl/debug.cpp
source/glsl/optimize.cpp
source/materials/rendermethod.cpp
source/render/object.cpp
source/render/renderer.cpp
source/render/sequence.cpp
source/resources/resourcemanager.cpp

index 76d9552e1771530945f6f7bba02f79b70064b979..a79e1f8d9860d9e31cdde6baf083cb3423b6c392 100644 (file)
@@ -164,7 +164,7 @@ void Animation::add_keyframe(const Time::TimeDelta &t, const KeyFrame *kf, bool
        for(const auto &kvp: kf_uniforms)
        {
                if(find_member(uniforms, kvp.first, &UniformInfo::name)==uniforms.end())
-                       uniforms.push_back(UniformInfo(kvp.first, kvp.second.size));
+                       uniforms.emplace_back(kvp.first, kvp.second.size);
        }
 }
 
@@ -246,17 +246,17 @@ void Animation::create_curve(CurveTarget target, int component, const T &extract
                                {
                                        typename Knot::Value cv = knots.back().y;
                                        knots.back().y = (knots[knots.size()-2].y+cv*2.0)/3.0;
-                                       knots.push_back(Knot(x, (dvalue+cv*2.0)/3.0));
+                                       knots.emplace_back(x, (dvalue+cv*2.0/3.0));
                                }
                                else if(n_control==0 && !knots.empty())
                                {
                                        typename Knot::Value prev = knots.back().y;
-                                       knots.push_back(Knot(knots.back().x, (prev*2.0+dvalue)/3.0));
-                                       knots.push_back(Knot(x, (prev+dvalue*2.0)/3.0));
+                                       knots.emplace_back(knots.back().x, (prev*2.0+dvalue)/3.0);
+                                       knots.emplace_back(x, (prev+dvalue*2.0/3.0));
                                }
                                n_control = 0;
                        }
-                       knots.push_back(Knot(x, value));
+                       knots.emplace_back(x, value);
                }
        }
        
index 42605beaf8c1d86ce1bfb772293a126de8b80c2f..44b8e466542b61fa573d9336ab5dc1f6724bfc6f 100644 (file)
@@ -31,7 +31,7 @@ AnimationPlayer::Target &AnimationPlayer::play_(Placeable &obj, const Animation
        target.stacked = stacked;
        // TODO check for incompatible armature
        target.armature = anim.get_armature();
-       target.animations.push_back(PlayingAnimation(anim, speed));
+       target.animations.emplace_back(anim, speed);
        return target;
 }
 
index d8512d82143c1efe92cc9207033ae67acd485a33..acfffbf7b3cc2a53b9c1afb419842aac2b8e84c7 100644 (file)
@@ -8,7 +8,7 @@ namespace GL {
 
 Armature::Link &Armature::add_link()
 {
-       links.push_back(Link(string(), links.size()));
+       links.emplace_back(string(), links.size());
        return links.back();
 }
 
index 685f15421d6d726f34f6b73840a5f7ac96eb3e3f..a9328488cedc9bc12b5399bf55d2b032771dd52a 100644 (file)
@@ -274,7 +274,7 @@ void OpenGLProgram::query_uniforms()
                        if(len>3 && !strcmp(name+len-3, "[0]"))
                                name[len-3] = 0;
 
-                       rd.uniforms.push_back(ReflectData::UniformInfo());
+                       rd.uniforms.emplace_back();
                        ReflectData::UniformInfo &info = rd.uniforms.back();
                        info.name = name;
                        info.tag = name;
@@ -296,7 +296,7 @@ void OpenGLProgram::query_uniforms()
                query_uniform_blocks(uniforms_by_index);
        }
 
-       rd.uniform_blocks.push_back(ReflectData::UniformBlockInfo());
+       rd.uniform_blocks.emplace_back();
        ReflectData::UniformBlockInfo &default_block = rd.uniform_blocks.back();
 
        for(ReflectData::UniformInfo &u: rd.uniforms)
@@ -331,7 +331,7 @@ void OpenGLProgram::query_uniform_blocks(const vector<ReflectData::UniformInfo *
                char name[128];
                int len;
                glGetActiveUniformBlockName(id, i, sizeof(name), &len, name);
-               rd.uniform_blocks.push_back(ReflectData::UniformBlockInfo());
+               rd.uniform_blocks.emplace_back();
                ReflectData::UniformBlockInfo &info = rd.uniform_blocks.back();
                info.name = name;
 
@@ -408,7 +408,7 @@ void OpenGLProgram::query_attributes()
                        if(len>3 && !strcmp(name+len-3, "[0]"))
                                name[len-3] = 0;
 
-                       rd.attributes.push_back(ReflectData::AttributeInfo());
+                       rd.attributes.emplace_back();
                        ReflectData::AttributeInfo &info = rd.attributes.back();
                        info.name = name;
                        info.location = glGetAttribLocation(id, name);
index 3f96f0bbb9a8d85bf14efdd27be337ada6d837bc..2886e0a85ef1d2ee7963be95a3aa6d88eb13d27f 100644 (file)
@@ -185,7 +185,7 @@ void SequenceTemplate::ClearLoader::init_actions()
 
 void SequenceTemplate::ClearLoader::color(float r, float g, float b, float a)
 {
-       obj.clear_colors.push_back(Color(r, g, b, a));
+       obj.clear_colors.emplace_back(r, g, b, a);
 }
 
 void SequenceTemplate::ClearLoader::depth(float d)
index bc61e1db7173f141f609a346b180bc51675dc375..16b2fa79c7509a5ee38a6f912c5a2da0ebbf83ec 100644 (file)
@@ -113,7 +113,7 @@ void Program::collect_visited_blocks(const vector<SpirVModule::InstructionBlock>
 void Program::collect_uniforms(const SpirVModule &mod, const vector<uint8_t> &used_variables)
 {
        // Prepare the default block
-       reflect_data.uniform_blocks.push_back(ReflectData::UniformBlockInfo());
+       reflect_data.uniform_blocks.emplace_back();
        vector<vector<string> > block_uniform_names(1);
 
        const vector<SpirVModule::Variable> &variables = mod.get_variables();
@@ -126,7 +126,7 @@ void Program::collect_uniforms(const SpirVModule &mod, const vector<uint8_t> &us
                const SpirVModule::Variable &v = variables[i];
                if((v.storage==SpirVModule::UNIFORM || v.storage==SpirVModule::PUSH_CONSTANT) && v.struct_type)
                {
-                       reflect_data.uniform_blocks.push_back(ReflectData::UniformBlockInfo());
+                       reflect_data.uniform_blocks.emplace_back();
                        ReflectData::UniformBlockInfo &info = reflect_data.uniform_blocks.back();
                        info.name = v.struct_type->name;
                        if(v.storage==SpirVModule::PUSH_CONSTANT)
@@ -144,13 +144,13 @@ void Program::collect_uniforms(const SpirVModule &mod, const vector<uint8_t> &us
                        string prefix;
                        if(!v.name.empty())
                                prefix = v.struct_type->name+".";
-                       block_uniform_names.push_back(vector<string>());
+                       block_uniform_names.emplace_back();
                        collect_block_uniforms(*v.struct_type, prefix, 0, block_uniform_names.back());
                }
                else if(v.storage==SpirVModule::UNIFORM_CONSTANT && (v.location>=0 || v.binding>=0))
                {
                        block_uniform_names[0].push_back(v.name);
-                       reflect_data.uniforms.push_back(ReflectData::UniformInfo());
+                       reflect_data.uniforms.emplace_back();
                        ReflectData::UniformInfo &info = reflect_data.uniforms.back();
                        info.name = v.name;
                        info.tag = v.name;
@@ -208,7 +208,7 @@ void Program::collect_block_uniforms(const SpirVModule::Structure &strct, const
                {
                        string name = prefix+m.name;
                        uniform_names.push_back(name);
-                       reflect_data.uniforms.push_back(ReflectData::UniformInfo());
+                       reflect_data.uniforms.emplace_back();
                        ReflectData::UniformInfo &info = reflect_data.uniforms.back();
                        info.name = name;
                        info.tag = name;
@@ -230,7 +230,7 @@ void Program::collect_attributes(const SpirVModule &mod, const vector<uint8_t> &
                        for(const SpirVModule::Variable *v: e.globals)
                                if(v->storage==SpirVModule::INPUT && used_variables[v-variables.data()])
                                {
-                                       reflect_data.attributes.push_back(ReflectData::AttributeInfo());
+                                       reflect_data.attributes.emplace_back();
                                        ReflectData::AttributeInfo &info = reflect_data.attributes.back();
                                        info.name = v->name;
                                        info.location = v->location;
index 5b142019150441f3fd7291f03db30473e401631b..60ac76f252594f79b823f30cc8c1f015766e4d92 100644 (file)
@@ -305,11 +305,11 @@ void DumpTree::visit(BasicTypeDeclaration &type)
 
        vector<Branch> branches;
        if(type.base_type)
-               branches.push_back(format("%s: %%%d %s", (type.kind==BasicTypeDeclaration::ALIAS ? "Alias of" : "Base"), get_label(*type.base_type), type.base_type->name));
+               branches.emplace_back(format("%s: %%%d %s", (type.kind==BasicTypeDeclaration::ALIAS ? "Alias of" : "Base"), get_label(*type.base_type), type.base_type->name));
        if(type.kind==BasicTypeDeclaration::VECTOR)
-               branches.push_back(format("Vector: %d", type.size));
+               branches.emplace_back(format("Vector: %d", type.size));
        else if(type.kind==BasicTypeDeclaration::MATRIX)
-               branches.push_back(format("Matrix: %dx%d", type.size&0xFFFF, type.size>>16));
+               branches.emplace_back(format("Matrix: %dx%d", type.size&0xFFFF, type.size>>16));
        append_subtree(branches);
 }
 
@@ -320,11 +320,11 @@ void DumpTree::visit(ImageTypeDeclaration &type)
        append(type, format("%%%d typedef %s", get_label(type), type.name));
 
        vector<Branch> branches;
-       branches.push_back(format("Dimensions: %s%s", dims[type.dimensions-1], (type.array ? " array" : "")));
+       branches.emplace_back(format("Dimensions: %s%s", dims[type.dimensions-1], (type.array ? " array" : "")));
        if(type.base_type)
-               branches.push_back(format("Element type: %%%d %s", get_label(*type.base_type), type.base_type->name));
+               branches.emplace_back(format("Element type: %%%d %s", get_label(*type.base_type), type.base_type->name));
        if(type.shadow)
-               branches.push_back("Shadow");
+               branches.emplace_back("Shadow");
        append_subtree(branches);
 }
 
@@ -362,7 +362,7 @@ void DumpTree::visit(VariableDeclaration &var)
        if(var.array)
        {
                if(var.array_size)
-                       branches.push_back(Branch("Array []", var.array_size.get()));
+                       branches.emplace_back("Array []", var.array_size.get());
                else
                        branches.push_back("Array []");
        }
@@ -421,10 +421,10 @@ void DumpTree::visit(Conditional &cond)
        append(cond, "if()");
 
        vector<Branch> branches;
-       branches.push_back(cond.condition.get());
-       branches.push_back(Branch("then", &cond.body));
+       branches.emplace_back(cond.condition.get());
+       branches.emplace_back("then", &cond.body);
        if(!cond.else_body.body.empty())
-               branches.push_back(Branch("else", &cond.else_body));
+               branches.emplace_back("else", &cond.else_body);
        append_subtree(branches);
 }
 
@@ -434,12 +434,12 @@ void DumpTree::visit(Iteration &iter)
 
        vector<Branch> branches;
        if(iter.init_statement)
-               branches.push_back(Branch("Initialization", iter.init_statement.get()));
+               branches.emplace_back("Initialization", iter.init_statement.get());
        if(iter.condition)
-               branches.push_back(Branch("Condition", iter.condition.get()));
+               branches.emplace_back("Condition", iter.condition.get());
        if(iter.loop_expression)
-               branches.push_back(Branch("Loop", iter.loop_expression.get()));
-       branches.push_back(&iter.body);
+               branches.emplace_back("Loop", iter.loop_expression.get());
+       branches.emplace_back(&iter.body);
        append_subtree(branches);
 }
 
index ea0f96f0e60920cba9dd23523e83c37a07133ffb..da95158903d2fea799d1aba55c3faca0762f7434 100644 (file)
@@ -449,7 +449,7 @@ void ExpressionInliner::visit(Assignment &assign)
                        if(targets_overlap(i->first, assign.target))
                                i->second->blocked = true;
 
-               expressions.push_back(ExpressionInfo());
+               expressions.emplace_back();
                ExpressionInfo &info = expressions.back();
                info.target = assign.target;
                // Self-referencing assignments can't be inlined without additional work.
@@ -496,7 +496,7 @@ void ExpressionInliner::visit(VariableDeclaration &var)
        analyze and non-trivial expressions could be expensive to inline.  */
        if((current_block->parent || (constant && r_trivial)) && var.interface.empty())
        {
-               expressions.push_back(ExpressionInfo());
+               expressions.emplace_back();
                ExpressionInfo &info = expressions.back();
                info.target = &var;
                /* Assume variables declared in an iteration initialization statement
@@ -1420,7 +1420,7 @@ void UnusedVariableRemover::visit(FunctionCall &call)
 
 void UnusedVariableRemover::record_assignment(const Assignment::Target &target, Node &node)
 {
-       assignments.push_back(AssignmentInfo());
+       assignments.emplace_back();
        AssignmentInfo &assign_info = assignments.back();
        assign_info.node = &node;
        assign_info.target = target;
index 5c838ef945624629483ea2fff992b1564285137a..ddbe4f1e457e83760dc699bce85ad52dd64ac29e 100644 (file)
@@ -81,7 +81,7 @@ void RenderMethod::set_texture(Tag tag, const Texture *tex, const Sampler *samp)
        auto i = find_member(textures, tag, &TextureSlot::tag);
        if(i==textures.end())
        {
-               textures.push_back(TextureSlot(tag));
+               textures.emplace_back(tag);
                i = textures.end()-1;
        }
        i->texture = tex;
@@ -216,7 +216,7 @@ void RenderMethod::Loader::texture(const string &n)
        auto i = find_member(obj.textures, Tag(n), &TextureSlot::tag);
        if(i==obj.textures.end())
        {
-               obj.textures.push_back(TextureSlot(n));
+               obj.textures.emplace_back(n);
                i = obj.textures.end()-1;
        }
        TextureSlot::Loader ldr(*i, n, coll);
index e2e95a9b024d25b610d256ef8c6678d7bb53ff89..65e9a7ef083fc52db1f899906b7febaed96264a5 100644 (file)
@@ -112,7 +112,7 @@ void Object::update_bounding_sphere()
                for(unsigned j=0; j<n_vertices; ++j)
                {
                        const float *v = reinterpret_cast<const float *>(vertices[j]+offset);
-                       points.push_back(Vector3(v[0], v[1], (three ? v[2] : 0.0f)));
+                       points.emplace_back(v[0], v[1], (three ? v[2] : 0.0f));
                }
        }
 
index 58a56ff2f2d105e5213e9b6a6cd837ea68f06e0e..45ad120045397de5848e4cecfe1968f39e83433b 100644 (file)
@@ -32,7 +32,7 @@ void Renderer::begin()
        if(current_state)
                throw invalid_operation("Renderer::begin");
 
-       state_stack.push_back(State());
+       state_stack.emplace_back();
        current_state = &state_stack.back();
 
        RendererBackend::begin();
@@ -163,7 +163,7 @@ void Renderer::set_texture(Tag tag, const Texture *tex, const Sampler *samp)
                        break;
                }
 
-       texture_stack.push_back(BoundTexture());
+       texture_stack.emplace_back();
        BoundTexture &bound_tex = texture_stack.back();
        bound_tex.tag = tag;
        bound_tex.texture = tex;
index 6c98b4023c293db017d8b43dcc3c9619dbeeacc4..74b8bc3b0b4fe9a6835d9f5fab5326dddcc62fe3 100644 (file)
@@ -65,7 +65,7 @@ void Sequence::set_clear_stencil(int s)
 
 Sequence::Step &Sequence::add_step(Tag tag, Renderable &r)
 {
-       steps.push_back(Step(tag, &r));
+       steps.emplace_back(tag, &r);
        return steps.back();
 }
 
index c72b361ce1f41ae9ec69d73d69a7d0e7307fcb21..91b374244090f78397b9cbfe78db63c36c97026b 100644 (file)
@@ -403,7 +403,7 @@ void ResourceManager::LoadingThread::main()
                        catch(const exception &e)
                        {
                                MutexLock lock(queue_mutex);
-                               error_queue.push_back(resource_load_error(managed->location.name, e));
+                               error_queue.emplace_back(managed->location.name, e);
                                managed->state = ManagedResource::LOAD_ERROR;
                        }