Kaynağa Gözat

realloc(): simplify aligned size calculations

Ioannis Koutras 11 yıl önce
ebeveyn
işleme
d961942625
1 değiştirilmiş dosya ile 8 ekleme ve 5 silme
  1. 8 5
      src/realloc.c

+ 8 - 5
src/realloc.c

@@ -80,8 +80,11 @@ void * realloc(void *ptr, size_t size) {
         size_t full_size = sizeof(raw_block_header_t) + req_padding(size);
         size_t full_size = sizeof(raw_block_header_t) + req_padding(size);
 
 
 #ifdef PAGESIZE_ALIGN
 #ifdef PAGESIZE_ALIGN
-        size_t pagesize = (size_t) sysconf(_SC_PAGESIZE);
-        full_size = pagesize * ((full_size + pagesize - 1) / pagesize);
+        full_size = (full_size + SYS_PAGESIZE - 1) &
+            (size_t) ~(SYS_PAGESIZE - 1);
+#else /* PAGESIZE_ALIGN */
+        full_size = (full_size + SYS_ALLOC_SIZE - 1) &
+            (size_t) ~(SYS_ALLOC_SIZE - 1);
 #endif /* PAGESIZE_ALIGN */
 #endif /* PAGESIZE_ALIGN */
 
 
         if(full_size < owner_raw_block->size) {
         if(full_size < owner_raw_block->size) {
@@ -104,9 +107,9 @@ void * realloc(void *ptr, size_t size) {
 
 
             // FIXME This is pagesize and mmap-specific
             // FIXME This is pagesize and mmap-specific
 #ifdef PAGESIZE_ALIGN
 #ifdef PAGESIZE_ALIGN
-            if(remaining_size > pagesize) {
-                remaining_size = pagesize * ((remaining_size + pagesize - 1) /
-                        pagesize);
+            if(remaining_size > SYS_PAGESIZE) {
+                remaining_size = (remaining_size + SYS_PAGESIZE - 1) &
+                    (size_t) ~(SYS_PAGESIZE - 1);
 
 
                 LOCK_RAW_BLOCK(owner_raw_block);
                 LOCK_RAW_BLOCK(owner_raw_block);
                 owner_raw_block->size = full_size;
                 owner_raw_block->size = full_size;