Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Ups, you may need this
[simgrid.git] / src / xbt / dynar.c
index be9fef6..41602f9 100644 (file)
@@ -11,7 +11,6 @@
 #include "xbt/misc.h"
 #include "xbt/sysdep.h"
 #include "xbt/log.h"
-#include "xbt/error.h"
 #include "xbt/dynar.h"
 #include <sys/types.h>
 
@@ -47,10 +46,9 @@ void _xbt_clear_mem(void * const ptr,
 }
 
 static _XBT_INLINE
-xbt_error_t
+void
 _xbt_dynar_expand(xbt_dynar_t const dynar,
                    const int          nb) {
-  xbt_error_t errcode     = no_error;
   const unsigned long old_size    = dynar->size;
 
   if (nb > old_size) {
@@ -79,8 +77,6 @@ _xbt_dynar_expand(xbt_dynar_t const dynar,
     dynar->size = new_size;
     dynar->data = new_data;
   }
-
-  return errcode;
 }
 
 static _XBT_INLINE
@@ -243,7 +239,7 @@ xbt_dynar_get_cpy(const xbt_dynar_t dynar,
  */
 void*
 xbt_dynar_get_ptr(const xbt_dynar_t dynar,
-                  const int          idx) {
+          const int          idx) {
 
   __sanity_check_dynar(dynar);
   __sanity_check_idx(idx);
@@ -364,29 +360,29 @@ xbt_dynar_remove_at(xbt_dynar_t  const dynar,
                      const int            idx,
                      void         * const object) {
 
+  unsigned long nb_shift;
+  unsigned long offset;
+
   __sanity_check_dynar(dynar);
   __sanity_check_idx(idx);
   __check_inbound_idx(dynar, idx);
 
-  if (object)
+  if (object) {
     _xbt_dynar_get_elm(object, dynar, idx);
+  } else if (dynar->free_f) {
+    char elm[SIZEOF_MAX];
+    _xbt_dynar_get_elm(elm, dynar, idx);
+    (*dynar->free_f)(elm);
+  }
 
-  {
-    const unsigned long old_used = dynar->used;
-    const unsigned long new_used = old_used - 1;
-
-    const unsigned long nb_shift =  old_used-1 - idx;
-    const unsigned long elmsize  =  dynar->elmsize;
-
-    const unsigned long offset   =  nb_shift*elmsize;
-
-    void * const elm_src  = _xbt_dynar_elm(dynar, idx+1);
-    void * const elm_dst  = _xbt_dynar_elm(dynar, idx);
+  nb_shift =  dynar->used-1 - idx;
+  offset   =  nb_shift * dynar->elmsize;
 
-    memmove(elm_dst, elm_src, offset);
+  memmove(_xbt_dynar_elm(dynar, idx),
+          _xbt_dynar_elm(dynar, idx+1), 
+          offset);
 
-    dynar->used = new_used;
-  }
+  dynar->used--;
 }
 
 /** @brief Make room at the end of the dynar for a new element, and return a pointer to it.
@@ -424,7 +420,7 @@ xbt_dynar_pop_ptr(xbt_dynar_t  const dynar) {
 /** @brief Get and remove the last element of the dynar */
 void
 xbt_dynar_pop(xbt_dynar_t  const dynar,
-               void         * const dst) {
+              void         * const dst) {
 
   /* sanity checks done by remove_at */
   DEBUG1("Pop %p",(void*)dynar);