Skip to content

Commit ad1392c

Browse files
committed
add comments
1 parent d84a909 commit ad1392c

File tree

2 files changed

+6
-5
lines changed

2 files changed

+6
-5
lines changed

inst/tests/tests.Rraw

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19067,6 +19067,7 @@ test(2281.2, fwrite(data.table(a=.POSIXct(0.0001)), dec=',', sep=';'), output="1
1906719067
# rbindlist(l, use.names=TRUE) should handle different colnames encodings #5452
1906819068
x = data.table(a = 1, b = 2, c = 3)
1906919069
y = data.table(x = 4, y = 5, z = 6)
19070+
# a-umlaut, o-umlaut, u-umlaut
1907019071
setnames(x , c("\u00e4", "\u00f6", "\u00fc"))
1907119072
setnames(y , iconv(c("\u00f6", "\u00fc", "\u00e4"), from = "UTF-8", to = "latin1"))
1907219073
test(2282.1, rbindlist(list(x,y), use.names=TRUE), data.table("\u00e4"=c(1,6), "\u00f6"=c(2,4), "\u00fc"=c(3,5)))

src/rbindlist.c

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,7 @@ SEXP rbindlist(SEXP l, SEXP usenamesArg, SEXP fillArg, SEXP idcolArg, SEXP ignor
7474
error(_("Failed to allocate upper bound of %"PRId64" unique column names [sum(lapply(l,ncol))]"), (int64_t)upperBoundUniqueNames);
7575
savetl_init();
7676
int nuniq=0;
77+
// first pass - gather unique column names
7778
for (int i=0; i<LENGTH(l); i++) {
7879
SEXP li = VECTOR_ELT(l, i);
7980
int thisncol=LENGTH(li);
@@ -89,11 +90,8 @@ SEXP rbindlist(SEXP l, SEXP usenamesArg, SEXP fillArg, SEXP idcolArg, SEXP ignor
8990
SET_TRUELENGTH(s,-nuniq);
9091
}
9192
}
92-
if (nuniq>0) {
93-
SEXP *tt = realloc(uniq, nuniq*sizeof(SEXP)); // shrink to only what we need to release the spare
94-
if (!tt) free(uniq); // shrink never fails; just keep codacy happy
95-
uniq = tt;
96-
}
93+
if (nuniq>0) uniq = realloc(uniq, nuniq*sizeof(SEXP)); // shrink to only what we need to release the spare
94+
9795
// now count the dups (if any) and how they're distributed across the items
9896
int *counts = (int *)calloc(nuniq, sizeof(int)); // counts of names for each colnames
9997
int *maxdup = (int *)calloc(nuniq, sizeof(int)); // the most number of dups for any name within one colname vector
@@ -105,6 +103,7 @@ SEXP rbindlist(SEXP l, SEXP usenamesArg, SEXP fillArg, SEXP idcolArg, SEXP ignor
105103
error(_("Failed to allocate nuniq=%d items working memory in rbindlist.c"), nuniq);
106104
// # nocov end
107105
}
106+
// second pass - count duplicates
108107
for (int i=0; i<LENGTH(l); i++) {
109108
SEXP li = VECTOR_ELT(l, i);
110109
int thisncol=length(li);
@@ -143,6 +142,7 @@ SEXP rbindlist(SEXP l, SEXP usenamesArg, SEXP fillArg, SEXP idcolArg, SEXP ignor
143142
for (int i=0; i<ncol; ++i) {uniqMap[i] = dupLink[i] = -1;}
144143
int nextCol=0, lastDup=ncol-1;
145144

145+
// third pass - create final column mapping colMapRaw
146146
for (int i=0; i<LENGTH(l); ++i) {
147147
SEXP li = VECTOR_ELT(l, i);
148148
int thisncol=length(li);

0 commit comments

Comments
 (0)