Skip to content

Commit 340e07b

Browse files
Merge pull request #980 from r-lib/f-558-prof
Refactor: better stack traces for profiling
2 parents bbc4eef + dbb867e commit 340e07b

File tree

3 files changed

+40
-27
lines changed

3 files changed

+40
-27
lines changed

R/nest.R

+26-17
Original file line numberDiff line numberDiff line change
@@ -250,13 +250,15 @@ add_terminal_token_after <- function(pd_flat) {
250250
filter(terminal) %>%
251251
arrange_pos_id()
252252

253-
new_tibble(list(
254-
pos_id = terminals$pos_id,
255-
token_after = lead(terminals$token, default = "")
256-
),
257-
nrow = nrow(terminals)
258-
) %>%
259-
left_join(pd_flat, ., by = "pos_id")
253+
rhs <- new_tibble(
254+
list(
255+
pos_id = terminals$pos_id,
256+
token_after = lead(terminals$token, default = "")
257+
),
258+
nrow = nrow(terminals)
259+
)
260+
261+
left_join(pd_flat, rhs, by = "pos_id")
260262
}
261263

262264
#' @rdname add_token_terminal
@@ -266,14 +268,15 @@ add_terminal_token_before <- function(pd_flat) {
266268
filter(terminal) %>%
267269
arrange_pos_id()
268270

269-
new_tibble(
271+
rhs <- new_tibble(
270272
list(
271273
id = terminals$id,
272274
token_before = lag(terminals$token, default = "")
273275
),
274276
nrow = nrow(terminals)
275-
) %>%
276-
left_join(pd_flat, ., by = "id")
277+
)
278+
279+
left_join(pd_flat, rhs, by = "id")
277280
}
278281

279282

@@ -351,13 +354,19 @@ nest_parse_data <- function(pd_flat) {
351354
internal$child <- NULL
352355

353356
child$parent_ <- child$parent
354-
joined <-
355-
child %>%
356-
nest_(., "child", setdiff(names(.), "parent_")) %>%
357-
left_join(internal, ., by = c("id" = "parent_"))
358-
nested <- joined
359-
nested$child <- map2(nested$child, nested$internal_child, combine_children)
360-
nested <- nested[, setdiff(names(nested), "internal_child")]
357+
358+
rhs <- nest_(child, "child", setdiff(names(child), "parent_"))
359+
360+
nested <- left_join(internal, rhs, by = c("id" = "parent_"))
361+
362+
children <- nested$child
363+
for (i in seq_along(children)) {
364+
new <- combine_children(children[[i]], nested$internal_child[[i]])
365+
# Work around is.null(new)
366+
children[i] <- list(new)
367+
}
368+
nested$child <- children
369+
nested$internal_child <- NULL
361370
nest_parse_data(nested)
362371
}
363372

R/roxygen-examples-parse.R

+2-3
Original file line numberDiff line numberDiff line change
@@ -146,9 +146,8 @@ emulate_rd <- function(roxygen) {
146146
text <- roxygen2::roc_proc_text(
147147
roxygen2::rd_roclet(),
148148
paste(roxygen, collapse = "\n")
149-
)[[1]]$get_section("examples") %>%
150-
as.character() %>%
151-
.[-1]
149+
)[[1]]$get_section("examples")
150+
text <- as.character(text)[-1]
152151
text <- c(
153152
if (grepl("^#'(\\s|\t)*@examples(\\s|\t)*$", roxygen[2])) "",
154153
text

R/transform-files.R

+12-7
Original file line numberDiff line numberDiff line change
@@ -244,15 +244,20 @@ parse_transform_serialize_r <- function(text,
244244
transformers
245245
)
246246

247-
text_out <- pd_nested %>%
248-
split(pd_nested$block) %>%
249-
unname() %>%
250-
map2(find_blank_lines_to_next_block(pd_nested),
251-
parse_transform_serialize_r_block,
247+
pd_split <- unname(split(pd_nested, pd_nested$block))
248+
pd_blank <- find_blank_lines_to_next_block(pd_nested)
249+
250+
text_out <- vector("list", length(pd_split))
251+
for (i in seq_along(pd_split)) {
252+
text_out[[i]] <- parse_transform_serialize_r_block(
253+
pd_split[[i]],
254+
pd_blank[[i]],
252255
transformers = transformers,
253256
base_indention = base_indention
254-
) %>%
255-
unlist()
257+
)
258+
}
259+
260+
text_out <- unlist(text_out)
256261

257262
verify_roundtrip(
258263
text, text_out,

0 commit comments

Comments
 (0)