From 3982e46d943ff32e6b656a0c6834adc5012d78a6 Mon Sep 17 00:00:00 2001 From: Hadley Wickham Date: Tue, 21 Jun 2022 17:00:13 -0500 Subject: [PATCH 1/2] Don't iterate into immediate bindings Fixes #48 --- src/size.cpp | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/src/size.cpp b/src/size.cpp index 1629bbe..904ba13 100644 --- a/src/size.cpp +++ b/src/size.cpp @@ -55,7 +55,7 @@ double obj_size_tree(SEXP x, if (!seen.insert(x).second) return 0; // Rcout << "\n" << std::string(depth * 2, ' '); - // Rprintf("type: %s", Rf_type2char(TYPEOF(x))); + // Rprintf("type: %s\n", Rf_type2char(TYPEOF(x))); // Use sizeof(SEXPREC) and sizeof(VECTOR_SEXPREC) computed in R. // CHARSXP are treated as vectors for this purpose @@ -136,8 +136,15 @@ double obj_size_tree(SEXP x, if (cons != x) { size += sizeof_node; } + size += obj_size_tree(TAG(cons), base_env, sizeof_node, sizeof_vector, seen, depth + 1); - size += obj_size_tree(CAR(cons), base_env, sizeof_node, sizeof_vector, seen, depth + 1); + + // In immediate bindings, the literal value is stored inside the CAR() so + // we don't want to iterate into it + // https://github.com/wch/r-source/blob/master/doc/notes/immbnd.md + if (!BNDCELL_TAG(cons)) { + size += obj_size_tree(CAR(cons), base_env, sizeof_node, sizeof_vector, seen, depth + 1); + } } // Handle non-nil CDRs size += obj_size_tree(cons, base_env, sizeof_node, sizeof_vector, seen, depth + 1); From 4d60ea529c7ef59c01142627ae918a08dc5ed050 Mon Sep 17 00:00:00 2001 From: Hadley Wickham Date: Tue, 21 Jun 2022 17:01:19 -0500 Subject: [PATCH 2/2] Add news bullet --- NEWS.md | 3 +++ 1 file changed, 3 insertions(+) diff --git a/NEWS.md b/NEWS.md index 58f7853..337e9c9 100644 --- a/NEWS.md +++ b/NEWS.md @@ -1,5 +1,8 @@ # lobstr (development version) +* `obj_size()` now works with "immediate bindings", which happen to be + used by sparklyr (#48). + * `ref()` lists all contents of environments even those with names beginning with `.` (@krlmlr, #53).