From 363e1dd46f67c046b150bd9826e76513506dec29 Mon Sep 17 00:00:00 2001
From: Christophe Geuzaine <cgeuzaine@ulg.ac.be>
Date: Sat, 3 Sep 2016 10:24:08 +0000
Subject: [PATCH] faster if no periodic vertices

---
 Geo/GModel.cpp | 38 ++++++++++++++++++++------------------
 1 file changed, 20 insertions(+), 18 deletions(-)

diff --git a/Geo/GModel.cpp b/Geo/GModel.cpp
index c0c3714127..0382980f94 100644
--- a/Geo/GModel.cpp
+++ b/Geo/GModel.cpp
@@ -1760,24 +1760,26 @@ int GModel::removeDuplicateMeshVertices(double tolerance)
     }
     // replace vertices in periodic copies
     std::map<MVertex*,MVertex*>& corrVtcs = ge->correspondingVertices;
-    std::map<MVertex*,MVertex*>::iterator cIter;
-    for (cIter = duplicates.begin(); cIter != duplicates.end(); ++cIter) {
-      MVertex* oldTgt = cIter->first;
-      MVertex* newTgt = cIter->second;
-      std::map<MVertex*, MVertex*>::iterator cvIter = corrVtcs.find(oldTgt);
-      if (cvIter != corrVtcs.end()) {
-        MVertex* src = cvIter->second;
-        corrVtcs.erase(cvIter);
-        corrVtcs[newTgt] = src;
-      }
-    }
-    for (cIter = corrVtcs.begin(); cIter != corrVtcs.end(); ++cIter) {
-      MVertex* oldSrc = cIter->second;
-      std::map<MVertex*,MVertex*>::iterator nIter = duplicates.find(oldSrc);
-      if (nIter != duplicates.end()) {
-        MVertex* tgt = cIter->first;
-        MVertex* newSrc = nIter->second;
-        corrVtcs[tgt] = newSrc;
+    if(corrVtcs.size()){
+      std::map<MVertex*,MVertex*>::iterator cIter;
+      for (cIter = duplicates.begin(); cIter != duplicates.end(); ++cIter) {
+        MVertex* oldTgt = cIter->first;
+        MVertex* newTgt = cIter->second;
+        std::map<MVertex*, MVertex*>::iterator cvIter = corrVtcs.find(oldTgt);
+        if (cvIter != corrVtcs.end()) {
+          MVertex* src = cvIter->second;
+          corrVtcs.erase(cvIter);
+          corrVtcs[newTgt] = src;
+        }
+      }
+      for (cIter = corrVtcs.begin(); cIter != corrVtcs.end(); ++cIter) {
+        MVertex* oldSrc = cIter->second;
+        std::map<MVertex*,MVertex*>::iterator nIter = duplicates.find(oldSrc);
+        if (nIter != duplicates.end()) {
+          MVertex* tgt = cIter->first;
+          MVertex* newSrc = nIter->second;
+          corrVtcs[tgt] = newSrc;
+        }
       }
     }
   }
-- 
GitLab