Browse Source

dyxlat: use xgrowarray

* dyxlat.c (dyxlat_alloc): Use xgrowarray instead of xcalloc.
(dyxlat_add_pair): Use xgrowarray instead of xreallocarray.
Dmitry V. Levin 2 years ago
parent
commit
f236207f46
1 changed files with 5 additions and 7 deletions
  1. 5
    7
      dyxlat.c

+ 5
- 7
dyxlat.c View File

@@ -44,8 +44,8 @@ dyxlat_alloc(const size_t nmemb)
44 44
 	struct dyxlat *const dyxlat = xmalloc(sizeof(*dyxlat));
45 45
 
46 46
 	dyxlat->used = 1;
47
-	dyxlat->allocated = nmemb ? nmemb : 16;
48
-	dyxlat->xlat = xcalloc(dyxlat->allocated, sizeof(struct xlat));
47
+	dyxlat->allocated = nmemb;
48
+	dyxlat->xlat = xgrowarray(NULL, &dyxlat->allocated, sizeof(struct xlat));
49 49
 	MARK_END(dyxlat->xlat[0]);
50 50
 
51 51
 	return dyxlat;
@@ -90,11 +90,9 @@ dyxlat_add_pair(struct dyxlat *const dyxlat, const uint64_t val,
90 90
 		}
91 91
 	}
92 92
 
93
-	if (dyxlat->used >= dyxlat->allocated) {
94
-		dyxlat->allocated *= 2;
95
-		dyxlat->xlat = xreallocarray(dyxlat->xlat, dyxlat->allocated,
96
-					     sizeof(struct xlat));
97
-	}
93
+	if (dyxlat->used >= dyxlat->allocated)
94
+		dyxlat->xlat = xgrowarray(dyxlat->xlat, &dyxlat->allocated,
95
+					  sizeof(struct xlat));
98 96
 
99 97
 	dyxlat->xlat[dyxlat->used - 1].val = val;
100 98
 	dyxlat->xlat[dyxlat->used - 1].str = xstrndup(str, len);

Loading…
Cancel
Save