Skip to content

Commit 3b08d35

Browse files
committed
Faster parse_transform_serialize_r_block()
1 parent 90df932 commit 3b08d35

File tree

2 files changed

+16
-7
lines changed

2 files changed

+16
-7
lines changed

R/transform-block.R

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,9 @@ parse_transform_serialize_r_block <- function(pd_nested,
2828
base_indention) {
2929
if (!all(pd_nested$is_cached, na.rm = TRUE) || !cache_is_activated()) {
3030
transformed_pd <- apply_transformers(pd_nested, transformers)
31-
flattened_pd <- post_visit_one(transformed_pd, extract_terminals) %>%
31+
flattened_pd <-
32+
# Special transformer: returns a list of pd
33+
vec_rbind(!!!post_visit_one(transformed_pd, extract_terminals)) %>%
3234
enrich_terminals(transformers$use_raw_indention) %>%
3335
apply_ref_indention() %>%
3436
set_regex_indention(

R/visit.R

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -188,12 +188,19 @@ context_towards_terminals <- function(pd_nested,
188188
#' @param pd_nested A nested parse table.
189189
#' @keywords internal
190190
extract_terminals <- function(pd_nested) {
191-
vec_rbind(
192-
!!!ifelse(pd_nested$terminal | pd_nested$is_cached,
193-
split(pd_nested, seq_len(nrow(pd_nested))),
194-
pd_nested$child
195-
)
196-
)
191+
terminal <- pd_nested$terminal
192+
is_cached <- pd_nested$is_cached
193+
194+
child <- pd_nested$child
195+
196+
for (i in seq_len(nrow(pd_nested))) {
197+
if (terminal[[i]] || is_cached[[i]]) {
198+
child[[i]] <- list(pd_nested[i, ])
199+
}
200+
}
201+
202+
# child is a list of data frame lists here
203+
unlist(unname(child), recursive = FALSE)
197204
}
198205

199206
#' Enrich flattened parse table

0 commit comments

Comments
 (0)