Skip to content

Commit 3c66757

Browse files
committed
mergeIndexAttrib: switch to R_mapAttrib
1 parent e4f1788 commit 3c66757

File tree

1 file changed

+8
-5
lines changed

1 file changed

+8
-5
lines changed

src/mergelist.c

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,18 +17,21 @@ SEXP copyCols(SEXP x, SEXP cols) {
1717
return R_NilValue;
1818
}
1919

20+
static SEXP setDuplicateOneAttrib(SEXP key, SEXP val, void *x) {
21+
setAttrib(x, PROTECT(key), PROTECT(shallow_duplicate(val)));
22+
UNPROTECT(2);
23+
return NULL; // continue
24+
}
25+
2026
void mergeIndexAttrib(SEXP to, SEXP from) {
2127
if (!isInteger(to) || LENGTH(to)!=0)
2228
internal_error(__func__, "'to' must be integer() already"); // # nocov
2329
if (isNull(from))
2430
return;
2531
if (!ANY_ATTRIB(to)) // target has no attributes -> overwrite
2632
SHALLOW_DUPLICATE_ATTRIB(to, from);
27-
else {
28-
SEXP t = ATTRIB(to), f = ATTRIB(from);
29-
for (; CDR(t) != R_NilValue; t = CDR(t)); // traverse to end of attributes list of to
30-
SETCDR(t, shallow_duplicate(f));
31-
}
33+
else
34+
R_mapAttrib(from, setDuplicateOneAttrib, to);
3235
}
3336

3437
SEXP cbindlist(SEXP x, SEXP copyArg) {

0 commit comments

Comments
 (0)