|
@@ -24,55 +24,12 @@
|
|
|
|
|
|
#include "bitmap/bitmap.h"
|
|
|
#include "dmmlib/dmmlib.h"
|
|
|
+#include "memmove.h"
|
|
|
|
|
|
#ifdef HAVE_LOCKS
|
|
|
#include <pthread.h>
|
|
|
#endif /* HAVE_LOCKS */
|
|
|
|
|
|
-/**
|
|
|
- * Implementation of memmove()
|
|
|
- *
|
|
|
- * Original code at:
|
|
|
- * http://discuss.joelonsoftware.com/default.asp?interview.11.437419.13
|
|
|
- */
|
|
|
-void * data_move(void *destination, void *source, size_t count);
|
|
|
-
|
|
|
-void * data_move(void *destination, void *source, size_t count) {
|
|
|
- size_t i = 0;
|
|
|
-
|
|
|
- char *src = (char *)source;
|
|
|
- char *dest = (char *)destination;
|
|
|
- void * ptr = dest;
|
|
|
-
|
|
|
- char * src_beg = src;
|
|
|
- char * src_end = src_beg + count;
|
|
|
-
|
|
|
- char * dest_beg = dest;
|
|
|
- char * dest_end = dest_beg + count;
|
|
|
- if(src == dest) {
|
|
|
- return ptr;
|
|
|
- }
|
|
|
-
|
|
|
- if((dest_beg >= src_beg && dest_beg <= src_end) || (dest_end >= src_beg && dest_end <= src_end)) {
|
|
|
-
|
|
|
- //Copy from higher addresses to lower addresses
|
|
|
- for( i = count ; i > 0 ; i--)
|
|
|
- {
|
|
|
- *(dest + i) = *(src + i);
|
|
|
- }
|
|
|
-
|
|
|
- return ptr;
|
|
|
- }
|
|
|
-
|
|
|
- //No overlap, copy from lower addresses to higher addresses
|
|
|
- for( i = 0 ; i < count ; i++)
|
|
|
- {
|
|
|
- *(dest + i) = *(src + i);
|
|
|
- }
|
|
|
-
|
|
|
- return ptr;
|
|
|
-}
|
|
|
-
|
|
|
/**
|
|
|
* Reallocates a memory block from a bitmap-organized raw block
|
|
|
*
|
|
@@ -93,10 +50,10 @@ void * bitmap_realloc(bitmap_rb_t *raw_block, void * ptr,
|
|
|
|
|
|
if(req_size > chunk_header->num_of_cells * raw_block->bytes_per_cell -
|
|
|
CHUNK_HDR_SIZE) {
|
|
|
- ret = data_move(ret, ptr, chunk_header->num_of_cells *
|
|
|
- raw_block->bytes_per_cell - CHUNK_HDR_SIZE);
|
|
|
+ memmove(ret, ptr, chunk_header->num_of_cells * raw_block->bytes_per_cell
|
|
|
+ - CHUNK_HDR_SIZE);
|
|
|
} else {
|
|
|
- ret = data_move(ret, ptr, req_size);
|
|
|
+ memmove(ret, ptr, req_size);
|
|
|
}
|
|
|
|
|
|
#ifdef HAVE_LOCKS
|