Skip to content

Commit 3c31188

Browse files
minor speed improvements by simplification
(1-2%)
1 parent f81ff7a commit 3c31188

File tree

3 files changed

+7
-5
lines changed

3 files changed

+7
-5
lines changed

R/indent.R

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -306,7 +306,7 @@ pd_is_multi_line <- function(pd) {
306306
#' @seealso choose_indention
307307
#' @keywords internal
308308
update_newlines <- function(pd) {
309-
npd <- nrow(pd) - 1
310-
pd$newlines[seq_len(npd)] <- pd$lag_newlines[seq_len(npd) + 1]
309+
seq_pd <- seq_len(nrow(pd) - 1)
310+
pd$newlines[seq_pd] <- pd$lag_newlines[seq_pd + 1]
311311
pd
312312
}

R/initialize.R

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,8 +52,7 @@ initialize_spaces <- function(pd_flat) {
5252
rep(0L, nrow(pd_flat)), pd_flat$col2
5353
)
5454
pd_flat$spaces <- pd_flat$col3 - pd_flat$col2_nl - 1L
55-
pd_flat$col3 <- NULL
56-
pd_flat$col2_nl <- NULL
55+
pd_flat$col3 <- pd_flat$col2_nl <- NULL
5756
pd_flat
5857
}
5958

R/transform-files.R

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -259,7 +259,10 @@ parse_transform_serialize_r <- function(text,
259259
apply_transformers <- function(pd_nested, transformers) {
260260
transformed_updated_multi_line <- post_visit(
261261
pd_nested,
262-
c(transformers$initialize, transformers$line_break, set_multi_line, update_newlines)
262+
c(
263+
transformers$initialize, transformers$line_break, set_multi_line,
264+
if (!is.null(transformers$line_break)) update_newlines
265+
)
263266
)
264267

265268
transformed_all <- pre_visit(

0 commit comments

Comments
 (0)