Skip to content

Commit

Permalink
Vectorise str_replace_all() (#2416)
Browse files Browse the repository at this point in the history
In the development version of stringr, I'm exploring vectorising the function form of `str_replace_all()` (https://github.com/tidyverse/stringr/pull/4620) because it offers considerable performance improvements. This patch quickly hacks rmarkdown to work with this change. It would probably be worthwhile to vectorise the two users of `process_html_res()` as that is likely to give a small, but meaningful, performance boost when there are many matches.
  • Loading branch information
hadley authored Oct 4, 2022
1 parent 86c364c commit f764a66
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion R/base64.R
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,11 @@ process_html_res <- function(html, reg, processor) {
html <- one_string(html)
process_img_src <- function(img_src) {
src <- sub(reg, '\\1', img_src)
processor(img_src, src)
vapply(
seq_along(img_src),
function(i) processor(img_src[[i]], src[[i]]),
character(1)
)
}
html <- stringr::str_replace_all(html, reg, process_img_src)
strsplit(html, "\n", fixed = TRUE)[[1]]
Expand Down

0 comments on commit f764a66

Please sign in to comment.