From: Egor Date: Sun, 2 Mar 2025 18:05:00 +0000 (+0200) Subject: map: move map_value into the class X-Git-Url: https://git.patchysicp.xyz/?a=commitdiff_plain;h=39b376281208a732f021ddd7c721a76ca031ce18;p=patchyircd.git map: move map_value into the class --- diff --git a/src/map.cpp b/src/map.cpp index 20ba22e..2111e80 100644 --- a/src/map.cpp +++ b/src/map.cpp @@ -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; diff --git a/src/map.h b/src/map.h index 07b272a..9dd1d8c 100644 --- a/src/map.h +++ b/src/map.h @@ -14,12 +14,12 @@ * 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) */