diff array.c @ 26:4fd9ecbbb143

Code cosmetic
author David Demelier <markand@malikania.fr>
date Sun, 18 Sep 2011 14:09:37 +0200
parents e09000fc013a
children 904a373aa120
line wrap: on
line diff
--- a/array.c	Thu Sep 15 17:53:43 2011 +0200
+++ b/array.c	Sun Sep 18 14:09:37 2011 +0200
@@ -55,8 +55,7 @@
 /*
  * Add to the head of array. NOTE: this may be very slow when adding a lot
  * of object (about 100000). If you need to add a lot of data please consider
- * using linked list instead or use array_append and then use reverse foreach
- * functions.
+ * using linked list instead.
  */
 
 int
@@ -72,9 +71,8 @@
 }
 
 /*
- * Insert the data to the specified index. The function returns -1 on
- * allocation failure if the array need to grow or when the index is out
- * of bounds otherwise 0 is returned.
+ * Insert the data at the specified index. The function returns -1 on
+ * allocation failure or when the index is outof bounds otherwise 0 is returned.
  */
 
 int
@@ -83,8 +81,8 @@
 	if (index > arr->length - 1 || index < 0 || array_grow(arr) < 0)
 		return -1;
 
-	memmove((char *) arr->data + SIZE(index + 1), (char *) arr->data + SIZE(index),
-	    SIZE(arr->length++ - index));
+	memmove((char *) arr->data + SIZE(index + 1),
+	    (char *) arr->data + SIZE(index), SIZE(arr->length++ - index));
 	memcpy((char *) arr->data + SIZE(index), data, arr->unit);
 
 	return 0;
@@ -159,8 +157,8 @@
 		return NULL;
 
 	data = (char *) arr->data + SIZE(index);
-	memmove((char *) arr->data + SIZE(index), (char *) arr->data + SIZE(index + 1),
-	    SIZE(arr->length - index));
+	memmove((char *) arr->data + SIZE(index),
+	    (char *) arr->data + SIZE(index + 1), SIZE(arr->length - index));
 	memset((char *) arr->data + SIZE(--arr->length), 0, arr->unit);
 
 	return data;
@@ -176,7 +174,7 @@
 array_swap(struct array *arr, int i1, int i2)
 {
 	/* Out of bounds */
-	if (i1 > arr->length - 1|| i1 < 0 || i2 > arr->length - 1|| i2 < 0)
+	if (i1 > arr->length - 1|| i1 < 0 || i2 > arr->length - 1 || i2 < 0)
 		return -1;
 
 	/*
@@ -188,7 +186,8 @@
 		return -1;
 
 	memcpy((char *) arr->tmp, (char *) arr->data + SIZE(i1), arr->unit);
-	memcpy((char *) arr->data + SIZE(i1), (char *) arr->data + SIZE(i2), arr->unit);
+	memcpy((char *) arr->data + SIZE(i1), (char *) arr->data + SIZE(i2),
+	    arr->unit);
 	memcpy((char *) arr->data + SIZE(i2), (char *) arr->tmp, arr->unit);
 
 	return 0;
@@ -282,7 +281,7 @@
 
 		arr->size += SIZE(arr->bsize);
 	} else
-		return ((arr->size / arr->unit) <= (size_t) arr->length) ? -1 : 0;
+		return (arr->size / arr->unit <= (size_t) arr->length) ? -1 : 0;
 
 	return 0;
 }