From: Mikko Rasa Date: Tue, 12 Dec 2023 22:22:18 +0000 (+0200) Subject: Use emplace_back and move semantics where applicable X-Git-Url: https://git.tdb.fi/?a=commitdiff_plain;h=c75642754dde7ca80f92623f409f9c41d81f7965;p=libs%2Fgl.git Use emplace_back and move semantics where applicable --- diff --git a/source/animation/animation.cpp b/source/animation/animation.cpp index 02a0c657..a4b801c8 100644 --- a/source/animation/animation.cpp +++ b/source/animation/animation.cpp @@ -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 diff --git a/source/animation/armature.cpp b/source/animation/armature.cpp index 8de888b3..558d2138 100644 --- a/source/animation/armature.cpp +++ b/source/animation/armature.cpp @@ -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)); } diff --git a/source/backends/opengl/program_backend.cpp b/source/backends/opengl/program_backend.cpp index 2bc43899..732967d2 100644 --- a/source/backends/opengl/program_backend.cpp +++ b/source/backends/opengl/program_backend.cpp @@ -563,7 +563,7 @@ void OpenGLProgram::finalize_uniforms() func = &uniform_matrix_wrapper; 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) diff --git a/source/builders/sequencetemplate.cpp b/source/builders/sequencetemplate.cpp index ec24ccad..a9e0a036 100644 --- a/source/builders/sequencetemplate.cpp +++ b/source/builders/sequencetemplate.cpp @@ -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)); } diff --git a/source/core/module.cpp b/source/core/module.cpp index 249ee0ff..412cc27a 100644 --- a/source/core/module.cpp +++ b/source/core/module.cpp @@ -155,19 +155,19 @@ void SpirVModule::reflect() reflection.reflect_code(code); map 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 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 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 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) diff --git a/source/core/program.cpp b/source/core/program.cpp index 9f014aae..7954ff5d 100644 --- a/source/core/program.cpp +++ b/source/core/program.cpp @@ -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; diff --git a/source/effects/shadowmap.cpp b/source/effects/shadowmap.cpp index c0c308c2..6dd797aa 100644 --- a/source/effects/shadowmap.cpp +++ b/source/effects/shadowmap.cpp @@ -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()); diff --git a/source/materials/technique.cpp b/source/materials/technique.cpp index ada0e8bb..5f77db86 100644 --- a/source/materials/technique.cpp +++ b/source/materials/technique.cpp @@ -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)); } diff --git a/source/render/sequence.h b/source/render/sequence.h index 8fa398a7..72ec5794 100644 --- a/source/render/sequence.h +++ b/source/render/sequence.h @@ -115,7 +115,7 @@ public: /** Adds an owned object, which will be deleted together with the sequence. */ template void add_owned(T *p) - { owned_data.push_back({ p, [](void *ptr){ delete static_cast(ptr); } }); } + { owned_data.emplace_back(p, [](void *ptr){ delete static_cast(ptr); }); } void setup_frame(Renderer &) override; void finish_frame() override;