Skip to content

Commit a2b6926

Browse files
committed
rbindlist: drop 'uniq'
Turns out it wasn't used.
1 parent ead1859 commit a2b6926

File tree

1 file changed

+4
-8
lines changed

1 file changed

+4
-8
lines changed

src/rbindlist.c

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -71,9 +71,6 @@ SEXP rbindlist(SEXP l, SEXP usenamesArg, SEXP fillArg, SEXP idcolArg, SEXP ignor
7171
// here we proceed as if fill=true for brevity (accounting for dups is tricky) and then catch any missings after this branch
7272
// when use.names==NA we also proceed here as if use.names was TRUE to save new code and then check afterwards the map is 1:ncol for every item
7373
// first find number of unique column names present; i.e. length(unique(unlist(lapply(l,names))))
74-
SEXP *uniq = malloc(sizeof(*uniq) * upperBoundUniqueNames); // upperBoundUniqueNames was initialized with 1 to ensure this is defined (otherwise 0 when no item has names)
75-
if (!uniq)
76-
error(_("Failed to allocate upper bound of %"PRId64" unique column names [sum(lapply(l,ncol))]"), (int64_t)upperBoundUniqueNames); // # nocov
7774
hashtab * marks = hash_create(upperBoundUniqueNames);
7875
PROTECT(marks->prot);
7976
int nuniq=0;
@@ -88,18 +85,17 @@ SEXP rbindlist(SEXP l, SEXP usenamesArg, SEXP fillArg, SEXP idcolArg, SEXP ignor
8885
for (int j=0; j<thisncol; j++) {
8986
SEXP s = ENC2UTF8(cnp[j]); // convert different encodings for use.names #5452
9087
if (hash_lookup(marks, s, 0)<0) continue; // seen this name before
91-
uniq[nuniq++] = s;
88+
nuniq++;
9289
hash_set(marks, s,-nuniq);
9390
}
9491
}
95-
if (nuniq>0) uniq = realloc(uniq, sizeof(SEXP)*nuniq); // shrink to only what we need to release the spare
9692

9793
// now count the dups (if any) and how they're distributed across the items
9894
int *counts = calloc(nuniq, sizeof(*counts)); // counts of names for each colnames
9995
int *maxdup = calloc(nuniq, sizeof(*maxdup)); // the most number of dups for any name within one colname vector
10096
if (!counts || !maxdup) {
10197
// # nocov start
102-
free(uniq); free(counts); free(maxdup);
98+
free(counts); free(maxdup);
10399
error(_("Failed to allocate nuniq=%d items working memory in rbindlist.c"), nuniq);
104100
// # nocov end
105101
}
@@ -132,7 +128,7 @@ SEXP rbindlist(SEXP l, SEXP usenamesArg, SEXP fillArg, SEXP idcolArg, SEXP ignor
132128
int *dupLink = malloc(sizeof(*dupLink) * ncol); // if a colname has occurred before (a dup) links from the 1st to the 2nd time in the final result, 2nd to 3rd, etc
133129
if (!colMapRaw || !uniqMap || !dupLink) {
134130
// # nocov start
135-
free(uniq); free(counts); free(colMapRaw); free(uniqMap); free(dupLink);
131+
free(counts); free(colMapRaw); free(uniqMap); free(dupLink);
136132
error(_("Failed to allocate ncol=%d items working memory in rbindlist.c"), ncol);
137133
// # nocov end
138134
}
@@ -170,7 +166,7 @@ SEXP rbindlist(SEXP l, SEXP usenamesArg, SEXP fillArg, SEXP idcolArg, SEXP ignor
170166
}
171167
}
172168
}
173-
free(uniq); free(counts); free(uniqMap); free(dupLink); // all local scope so no need to set to NULL
169+
free(counts); free(uniqMap); free(dupLink); // all local scope so no need to set to NULL
174170

175171
UNPROTECT(1); // marks
176172
// colMapRaw is still allocated. It was allocated with malloc because we needed to catch if the alloc failed.

0 commit comments

Comments
 (0)