src/array_list.c

changeset 1084
0bcd71d2615a
parent 1065
6eb7b54975ee
child 1089
865c84fef6b4
--- a/src/array_list.c	Sat Jan 04 11:55:31 2025 +0100
+++ b/src/array_list.c	Sat Jan 04 12:31:28 2025 +0100
@@ -132,21 +132,21 @@
     size_t oldcap;
     size_t oldsize;
     size_t max_size;
-    if (width == 0 || width == 8*sizeof(size_t)) {
+    if (width == 0 || width == sizeof(size_t)) {
         oldcap = *(size_t*) capacity;
         oldsize = *(size_t*) size;
         max_size = SIZE_MAX;
-    } else if (width == 16) {
+    } else if (width == sizeof(uint16_t)) {
         oldcap = *(uint16_t*) capacity;
         oldsize = *(uint16_t*) size;
         max_size = UINT16_MAX;
-    } else if (width == 8) {
+    } else if (width == sizeof(uint8_t)) {
         oldcap = *(uint8_t*) capacity;
         oldsize = *(uint8_t*) size;
         max_size = UINT8_MAX;
     }
 #if CX_WORDSIZE == 64
-    else if (width == 32) {
+    else if (width == sizeof(uint32_t)) {
         oldcap = *(uint32_t*) capacity;
         oldsize = *(uint32_t*) size;
         max_size = UINT32_MAX;
@@ -186,15 +186,15 @@
         *array = newmem;
 
         // store new capacity
-        if (width == 0 || width == 8*sizeof(size_t)) {
+        if (width == 0 || width == sizeof(size_t)) {
             *(size_t*) capacity = newcap;
-        } else if (width == 16) {
+        } else if (width == sizeof(uint16_t)) {
             *(uint16_t*) capacity = (uint16_t) newcap;
-        } else if (width == 8) {
+        } else if (width == sizeof(uint8_t)) {
             *(uint8_t*) capacity = (uint8_t) newcap;
         }
 #if CX_WORDSIZE == 64
-        else if (width == 32) {
+        else if (width == sizeof(uint32_t)) {
             *(uint32_t*) capacity = (uint32_t) newcap;
         }
 #endif
@@ -225,21 +225,21 @@
     size_t oldcap;
     size_t oldsize;
     size_t max_size;
-    if (width == 0 || width == 8*sizeof(size_t)) {
+    if (width == 0 || width == sizeof(size_t)) {
         oldcap = *(size_t*) capacity;
         oldsize = *(size_t*) size;
         max_size = SIZE_MAX;
-    } else if (width == 16) {
+    } else if (width == sizeof(uint16_t)) {
         oldcap = *(uint16_t*) capacity;
         oldsize = *(uint16_t*) size;
         max_size = UINT16_MAX;
-    } else if (width == 8) {
+    } else if (width == sizeof(uint8_t)) {
         oldcap = *(uint8_t*) capacity;
         oldsize = *(uint8_t*) size;
         max_size = UINT8_MAX;
     }
 #if CX_WORDSIZE == 64
-    else if (width == 32) {
+    else if (width == sizeof(uint32_t)) {
         oldcap = *(uint32_t*) capacity;
         oldsize = *(uint32_t*) size;
         max_size = UINT32_MAX;
@@ -303,18 +303,18 @@
 
     // if any of size or capacity changed, store them back
     if (newsize != oldsize || newcap != oldcap) {
-        if (width == 0 || width == 8*sizeof(size_t)) {
+        if (width == 0 || width == sizeof(size_t)) {
             *(size_t*) capacity = newcap;
             *(size_t*) size = newsize;
-        } else if (width == 16) {
+        } else if (width == sizeof(uint16_t)) {
             *(uint16_t*) capacity = (uint16_t) newcap;
             *(uint16_t*) size = (uint16_t) newsize;
-        } else if (width == 8) {
+        } else if (width == sizeof(uint8_t)) {
             *(uint8_t*) capacity = (uint8_t) newcap;
             *(uint8_t*) size = (uint8_t) newsize;
         }
 #if CX_WORDSIZE == 64
-        else if (width == 32) {
+        else if (width == sizeof(uint32_t)) {
             *(uint32_t*) capacity = (uint32_t) newcap;
             *(uint32_t*) size = (uint32_t) newsize;
         }

mercurial