Skip to content

Commit 885ecc9

Browse files
adapt test: now only 3x faster, previously 5x.
1 parent 9d20e91 commit 885ecc9

File tree

2 files changed

+6
-7
lines changed

2 files changed

+6
-7
lines changed

R/nest.R

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -116,13 +116,12 @@ drop_cached_children <- function(pd) {
116116
#' top level expression, potentially cached.
117117
#' @keywords internal
118118
find_pos_id_to_keep <- function(pd) {
119-
if (pd$is_cached[1]) {
120-
idx_comment <- which(pd$token == "COMMENT")
121-
pd$pos_id[unique(c(1, idx_comment))]
122-
} else {
123-
pd$pos_id
124-
}
119+
if (pd$is_cached[1]) {
120+
pd$pos_id[c(TRUE, pd[-1L, "token"] == "COMMENT")]
121+
} else {
122+
pd$pos_id
125123
}
124+
}
126125

127126

128127
#' Turn off styling for parts of the code

tests/testthat/test-cache-with-r-cache.R

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ test_that("top-level test: Caches top-level expressions efficiently on style_tex
5656
cache_deactivate()
5757
not_cached_benchmark <- system.time(style_text(text_styled))
5858
expect_lt(
59-
partially_cached_benchmark['elapsed'] * 5,
59+
partially_cached_benchmark['elapsed'] * 3,
6060
not_cached_benchmark['elapsed']
6161
)
6262
})

0 commit comments

Comments
 (0)