Skip to content

Commit 15aa397

Browse files
committed
rbindlist(): better initial allocation size
Also adjust the minimal hash table size to avoid shift overflow on size=0 and free=0 on size=1.
1 parent 860e2ff commit 15aa397

File tree

2 files changed

+2
-2
lines changed

2 files changed

+2
-2
lines changed

src/hash.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ struct hash_tab {
1515
static const double default_load_factor = .75;
1616

1717
static R_INLINE size_t get_next_pow2(size_t n) {
18-
if (n <= 1) return 1;
18+
if (n <= 2) return 2;
1919
n--;
2020
n |= n >> 1;
2121
n |= n >> 2;

src/rbindlist.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -356,7 +356,7 @@ SEXP rbindlist(SEXP l, SEXP usenamesArg, SEXP fillArg, SEXP idcolArg, SEXP ignor
356356
int ansloc=0;
357357
if (factor) {
358358
char warnStr[1000] = "";
359-
hashtab * marks = hash_create(1024);
359+
hashtab * marks = hash_create(xlength(longestLevels));
360360
int nLevel=0, allocLevel=0;
361361
SEXP *levelsRaw = NULL; // growing list of SEXP pointers. Raw since managed with raw realloc.
362362
if (orderedFactor) {

0 commit comments

Comments
 (0)