]> git.tdb.fi Git - libs/gl.git/commitdiff
Use emplace_back and move semantics where applicable
authorMikko Rasa <tdb@tdb.fi>
Tue, 12 Dec 2023 22:22:18 +0000 (00:22 +0200)
committerMikko Rasa <tdb@tdb.fi>
Tue, 12 Dec 2023 22:28:33 +0000 (00:28 +0200)
source/animation/animation.cpp
source/animation/armature.cpp
source/backends/opengl/program_backend.cpp
source/builders/sequencetemplate.cpp
source/core/module.cpp
source/core/program.cpp
source/effects/shadowmap.cpp
source/materials/technique.cpp
source/render/sequence.h

index 02a0c6576a5be8ccc6e03aae559a1049fe199a27..a4b801c8161754752dfa5ba6765c9e78c7578568 100644 (file)
@@ -290,7 +290,7 @@ void Animation::add_event(const Time::TimeDelta &t, const string &n, const Varia
        event.time = t;
        event.name = n;
        event.value = v;
-       events.push_back(event);
+       events.emplace_back(move(event));
 }
 
 const Time::TimeDelta &Animation::get_duration() const
index 8de888b3f51490df3df03e944d17d44ce565ddff..558d213834daffcf52ff646eeb247530d320c155 100644 (file)
@@ -63,7 +63,7 @@ void Armature::Loader::link(const string &n)
 {
        Link lnk(n, obj.links.size());
        sub(lnk).load(obj);
-       obj.links.push_back(lnk);
+       obj.links.emplace_back(move(lnk));
 }
 
 
index 2bc438990c25de4cc67b79f847edcefdb509b7b1..732967d28ea011529dbc99f4388ec861dc1acde1 100644 (file)
@@ -563,7 +563,7 @@ void OpenGLProgram::finalize_uniforms()
                                        func = &uniform_matrix_wrapper<float, glUniformMatrix4x3fv>;
 
                                if(func)
-                                       uniform_calls.push_back(UniformCall(u->location, u->array_size, func));
+                                       uniform_calls.emplace_back(u->location, u->array_size, func);
                        }
 
                if(i->data_size<=0)
index ec24ccad48eff1197d69d49f840a43fb4f8753e7..a9e0a0366ba9b33bb62f335f7c406bf73ecfc0e4 100644 (file)
@@ -145,7 +145,7 @@ void SequenceTemplate::Loader::step(const string &tag, const string &rend)
        stp.renderable_name = rend;
        sub(stp).name(format("step_%d", obj.steps.size())).load(get_collection());
 
-       obj.steps.push_back(stp);
+       obj.steps.push_back(move(stp));
 }
 
 
index 249ee0ff1f3c1b4e9a4375d6ddf345855570c997..412cc27a0d96479dcac5c1616ed2f439378a96ce 100644 (file)
@@ -155,19 +155,19 @@ void SpirVModule::reflect()
        reflection.reflect_code(code);
 
        map<const Constant *, unsigned> spec_indices;
-       for(const auto &kvp: reflection.constants)
+       for(auto &kvp: reflection.constants)
                if(kvp.second.constant_id>=0)
                {
                        spec_indices[&kvp.second] = spec_constants.size();
-                       spec_constants.push_back(kvp.second);
+                       spec_constants.emplace_back(move(kvp.second));
                }
 
        map<const Structure *, unsigned> struct_indices;
        structs.reserve(reflection.structs.size());
-       for(const auto &kvp: reflection.structs)
+       for(auto &kvp: reflection.structs)
        {
                struct_indices[&kvp.second] = structs.size();
-               structs.push_back(kvp.second);
+               structs.emplace_back(move(kvp.second));
        }
 
        for(Structure &s: structs)
@@ -199,7 +199,7 @@ void SpirVModule::reflect()
 
        map<const Variable *, unsigned> var_indices;
        variables.reserve(reflection.variables.size());
-       for(const auto &kvp: reflection.variables)
+       for(auto &kvp: reflection.variables)
        {
                auto i = find_if(variables, [&kvp](const Variable &v){ return v==kvp.second; });
                if(i!=variables.end())
@@ -207,7 +207,7 @@ void SpirVModule::reflect()
                else
                {
                        var_indices[&kvp.second] = variables.size();
-                       variables.push_back(kvp.second);
+                       variables.emplace_back(move(kvp.second));
                }
        }
 
@@ -219,9 +219,9 @@ void SpirVModule::reflect()
                }
 
        entry_points.reserve(reflection.entry_points.size());
-       for(const auto &kvp: reflection.entry_points)
+       for(auto &kvp: reflection.entry_points)
        {
-               entry_points.push_back(kvp.second);
+               entry_points.emplace_back(move(kvp.second));
                EntryPoint &entry = entry_points.back();
                for(const Variable *&v: entry.globals)
                {
@@ -232,10 +232,10 @@ void SpirVModule::reflect()
 
        map<const InstructionBlock *, unsigned> block_indices;
        blocks.reserve(reflection.blocks.size());
-       for(const auto &kvp: reflection.blocks)
+       for(auto &kvp: reflection.blocks)
        {
                block_indices[&kvp.second] = blocks.size();
-               blocks.push_back(kvp.second);
+               blocks.emplace_back(move(kvp.second));
        }
 
        for(InstructionBlock &b: blocks)
index 9f014aae71dbcfd411e6bf658cbf8c0c693a69d6..7954ff5d3c5c837a3995bb03e7bd55f9f0fe8893 100644 (file)
@@ -158,8 +158,8 @@ void Program::collect_block_uniforms(const SpirVModule::Structure &strct, const
                }
                else
                {
-                       string name = prefix+m.name;
-                       uniform_names.push_back(name);
+                       uniform_names.emplace_back(prefix+m.name);
+                       const string &name = uniform_names.back();
                        reflect_data.uniforms.emplace_back();
                        ReflectData::UniformInfo &info = reflect_data.uniforms.back();
                        info.name = name;
index c0c308c2a4a81ab1e9d7f2dc3aaadf0da50dc1ea..6dd797aa1d70f8c5508975a2d7ae252f7157cd20 100644 (file)
@@ -221,7 +221,7 @@ void ShadowMap::setup_frame(Renderer &renderer)
                }
 
                Matrix to_texcoord = Matrix().translate(Vector3(0.5f, 0.5f, 0.0f)).scale(Vector3(0.5f, 0.5f, 1.0f));
-               shadow_matrices.push_back(to_texcoord*v.camera.get_projection_matrix()*v.camera.get_view_matrix());
+               shadow_matrices.emplace_back(to_texcoord*v.camera.get_projection_matrix()*v.camera.get_view_matrix());
        }
 
        shdata.uniform_array("shd_world_matrix", shadow_matrices.size(), shadow_matrices.data());
index ada0e8bb6449f24a6770a99581027640333b9133..5f77db86b0abd77bc303573dbf48e7b464ef9a7d 100644 (file)
@@ -138,7 +138,7 @@ void Technique::Loader::method(const string &n)
        if(!p.get_shader_program())
                throw logic_error("no shader program in method");
 
-       insert_unique(obj.methods, n, p);
+       insert_unique(obj.methods, n, std::move(p));
 }
 
 
index 8fa398a7aaeed7e47d80f3ca9c72a228e87e29ca..72ec57941ade3d20f8ed15b4cca0e791790edc04 100644 (file)
@@ -115,7 +115,7 @@ public:
        /** Adds an owned object, which will be deleted together with the sequence. */
        template<typename T>
        void add_owned(T *p)
-       { owned_data.push_back({ p, [](void *ptr){ delete static_cast<T *>(ptr); } }); }
+       { owned_data.emplace_back(p, [](void *ptr){ delete static_cast<T *>(ptr); }); }
 
        void setup_frame(Renderer &) override;
        void finish_frame() override;