A
lgorithmique
N
umérique
D
istribuée
Public GIT Repository
projects
/
simgrid.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
This structure was not necessary
[simgrid.git]
/
src
/
xbt
/
dynar.c
diff --git
a/src/xbt/dynar.c
b/src/xbt/dynar.c
index
7c3bcc6
..
87d4aa8
100644
(file)
--- a/
src/xbt/dynar.c
+++ b/
src/xbt/dynar.c
@@
-86,27
+86,18
@@
static XBT_INLINE
const unsigned long old_size = dynar->size;
if (nb > old_size) {
const unsigned long old_size = dynar->size;
if (nb > old_size) {
- char *const old_data = (char *) dynar->data;
-
+ void *const old_data = dynar->data;
const unsigned long elmsize = dynar->elmsize;
const unsigned long elmsize = dynar->elmsize;
+ const unsigned long old_length = old_size * elmsize;
- const unsigned long used = dynar->used;
- const unsigned long used_length = used * elmsize;
-
- const unsigned long new_size =
- nb > (2 * (old_size + 1)) ? nb : (2 * (old_size + 1));
+ const unsigned long expand = 2 * (old_size + 1);
+ const unsigned long new_size = (nb > expand ? nb : expand);
const unsigned long new_length = new_size * elmsize;
const unsigned long new_length = new_size * elmsize;
- char *const new_data = (char *) xbt_malloc0(elmsize * new_size);
-
- XBT_DEBUG("expand %p from %lu to %lu elements", (void *) dynar,
- (unsigned long) old_size, nb);
+ void *const new_data = xbt_realloc(old_data, new_length);
- if (old_data) {
- memcpy(new_data, old_data, used_length);
- free(old_data);
- }
+ XBT_DEBUG("expand %p from %lu to %lu elements", dynar, old_size, new_size);
- _xbt_clear_mem(
new_data + used_length, new_length - use
d_length);
+ _xbt_clear_mem(
(char *)new_data + old_length, new_length - ol
d_length);
dynar->size = new_size;
dynar->data = new_data;
dynar->size = new_size;
dynar->data = new_data;
@@
-583,7
+574,8
@@
int xbt_dynar_member(xbt_dynar_t const dynar, void *const elem)
TRY {
xbt_dynar_search(dynar, elem);
TRY {
xbt_dynar_search(dynar, elem);
- } CATCH(e) {
+ }
+ CATCH(e) {
if (e.category == not_found_error) {
xbt_ex_free(e);
return 0;
if (e.category == not_found_error) {
xbt_ex_free(e);
return 0;
@@
-1332,7
+1324,7
@@
static void pusher_f(void *a)
static void poper_f(void *a)
{
xbt_dynar_t d = (xbt_dynar_t) a;
static void poper_f(void *a)
{
xbt_dynar_t d = (xbt_dynar_t) a;
- int i;
+
volatile
int i;
int data;
xbt_ex_t e;
int data;
xbt_ex_t e;