]> git.tdb.fi Git - libs/gltk.git/blobdiff - source/partcache.cpp
Minor refactoring
[libs/gltk.git] / source / partcache.cpp
index f4c085e5baa47c4230786eba92a2feb50ac8cf50..8b425c2b0a5f255c553d91e67fcca67497c6dd0a 100644 (file)
@@ -6,6 +6,24 @@ using namespace std;
 namespace Msp {
 namespace GLtk {
 
+CachedPart::CachedPart(CachedPart &&other):
+       part(other.part),
+       texture(other.texture),
+       mesh(other.mesh)
+{
+       other.mesh = nullptr;
+}
+
+CachedPart &CachedPart::operator=(CachedPart &&other)
+{
+       delete mesh;
+       part = other.part;
+       texture = other.texture;
+       mesh = other.mesh;
+       other.mesh = nullptr;
+       return *this;
+}
+
 CachedPart::~CachedPart()
 {
        delete mesh;
@@ -29,12 +47,9 @@ void PartCache::insert_special(const Part &part)
        if(!rebuilding)
                throw logic_error("!rebuilding");
 
-       for(current=next; current!=parts.end(); ++current)
-               if(current->part==&part)
-               {
-                       parts.erase(next, current);
-                       break;
-               }
+       current = find_if(next, parts.end(), [&part](const CachedPart &p){ return p.part==∂ });
+       if(current!=parts.end())
+               parts.erase(next, current);
 
        if(current==parts.end())
                current = parts.insert(next, CachedPart());