From 24c3985639f71087b5a2dac30ea0ea9af66e1266 Mon Sep 17 00:00:00 2001
From: Christophe Geuzaine <cgeuzaine@ulg.ac.be>
Date: Tue, 7 Jan 2014 06:29:37 +0000
Subject: [PATCH] simpler List_Put

---
 Common/ListUtils.cpp | 20 +++++++++++++-------
 1 file changed, 13 insertions(+), 7 deletions(-)

diff --git a/Common/ListUtils.cpp b/Common/ListUtils.cpp
index 20305e7872..03fcf4ce5f 100644
--- a/Common/ListUtils.cpp
+++ b/Common/ListUtils.cpp
@@ -132,14 +132,20 @@ void List_Write(List_T * liste, int index, void *data)
   }
 }
 
-void List_Put(List_T *liste, int index, void *data)
+void List_Put(List_T * liste, int index, void *data)
 {
-  liste->n += 1;
-  List_Realloc(liste, liste->n);
-  for(int j = 0; j < liste->n -1 - index; j++)
-    memcpy(List_Pointer_Fast(liste, liste->n - j - 1), List_Pointer_Fast(liste, liste->n - 1 - j - 1),
-           liste->size);
-  memcpy(&liste->array[index * liste->size], data, liste->size);
+  if(index < 0)
+    Msg::Error("Wrong list index (put)");
+  else {
+    if(index >= liste->n) {
+      liste->n = index + 1;
+      List_Realloc(liste, liste->n);
+      List_Write(liste, index, data);
+    }
+    else {
+      List_Write(liste, index, data);
+    }
+  }
 }
 
 void List_Pop(List_T * liste)
-- 
GitLab