]> PatchyGit - patchyircd.git/commitdiff
map: move map_value into the class
authorEgor <egor@patchysicp.xyz>
Sun, 2 Mar 2025 18:05:00 +0000 (20:05 +0200)
committerEgor <egor@patchysicp.xyz>
Sun, 2 Mar 2025 18:06:11 +0000 (20:06 +0200)
src/map.cpp
src/map.h

index 20ba22e..2111e80 100644 (file)
@@ -36,7 +36,7 @@ int map_base::_set(const char *key, const void *value, void **oldvalue)
                        *oldvalue = ptr[i].value;
                if (!value) {
                        free(ptr[i].key);
-                       memmove(ptr+i, ptr+i+1, sizeof(struct map_value)*(len-(i+1)));
+                       memmove(ptr+i, ptr+i+1, sizeof(map_value)*(len-(i+1)));
                        len--;
                } else {
                        ptr[i].value = (void *)value;
@@ -47,7 +47,7 @@ int map_base::_set(const char *key, const void *value, void **oldvalue)
                if (value) {
                        if (len == cap) {
                                int ncap = cap ? cap*2 : 2;
-                               struct map_value *nptr = (struct map_value *)realloc(ptr, sizeof(struct map_value)*ncap);
+                               map_value *nptr = (map_value *)realloc(ptr, sizeof(map_value)*ncap);
                                if (!nptr)
                                        return -1;
                                ptr = nptr;
@@ -58,7 +58,7 @@ int map_base::_set(const char *key, const void *value, void **oldvalue)
                        if (!nkey)
                                return -1;
                        memcpy(nkey, key, slen);
-                       memmove(ptr+i+1, ptr+i, sizeof(struct map_value)*(len-i));
+                       memmove(ptr+i+1, ptr+i, sizeof(map_value)*(len-i));
                        len++;
                        ptr[i].key = nkey;
                        ptr[i].value = (void *)value;
index 07b272a..9dd1d8c 100644 (file)
--- a/src/map.h
+++ b/src/map.h
  * A map is created by allocating and zero-initializing an object of type
  * map_t. All map functions take a pointer to map_t.
  */
-struct map_value {
-       char *key;
-       void *value;
-};
 struct map_base {
-       struct map_value *ptr;
+       struct map_value {
+               char *key;
+               void *value;
+       };
+       map_value *ptr;
        size_t len, cap;
        /* Return the associated value for a given key.
         * Dynarr complexity: O(log n) */