Skip to content

Commit ca437ba

Browse files
Merge pull request #691 from lorenzwalthert/minor-speed-improvements
- Minor speed improvements (#691).
2 parents f81ff7a + e7e9899 commit ca437ba

File tree

7 files changed

+18
-12
lines changed

7 files changed

+18
-12
lines changed

R/compat-dplyr.R

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -52,16 +52,17 @@ filter <- function(.data, ...) {
5252
subset(.data, ...)
5353
}
5454

55-
left_join <- function(x, y, by, ...) {
55+
left_join <- function(x, y, by) {
5656
if (rlang::is_named(by)) {
5757
by_x <- names(by)
5858
by_y <- unname(by)
5959
} else {
6060
by_x <- by_y <- by
6161
}
62-
res <- as_tibble(merge(x, y, by.x = by_x, by.y = by_y, all.x = TRUE, ...))
63-
res <- arrange(res, pos_id)
6462

63+
res <- merge(x, y, by.x = by_x, by.y = by_y, all.x = TRUE) %>%
64+
arrange_pos_id()
65+
res <- new_tibble(res, nrow = nrow(res))
6566
# dplyr::left_join set unknown list columns to NULL, merge sets them
6667
# to NA
6768
if (exists("child", res) && any(is.na(res$child))) {

R/compat-tidyr.R

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,5 +6,5 @@ nest_ <- function(data, key_col, nest_cols = character()) {
66
res <- list()
77
res[[key_column]] <- key_levels
88
res[[key_col]] <- split(data[, nest_cols], key_factor)
9-
as_tibble(res)
9+
new_tibble(res, nrow = length(key_levels))
1010
}

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/nest.R

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -312,14 +312,15 @@ remove_terminal_token_before_and_after <- function(pd_flat) {
312312
#' @return An integer vector of length spaces_after_prefix, which is either
313313
#' one (if `force_one = TRUE`) or `space_after_prefix` with all values
314314
#' below one set to one.
315+
#' @return
316+
#' Numeric vector indicating the number of spaces.
315317
#' @keywords internal
316318
set_spaces <- function(spaces_after_prefix, force_one) {
317319
if (force_one) {
318-
n_of_spaces <- rep(1, length(spaces_after_prefix))
320+
rep(1, length(spaces_after_prefix))
319321
} else {
320-
n_of_spaces <- pmax(spaces_after_prefix, 1L)
322+
pmax(spaces_after_prefix, 1L)
321323
}
322-
n_of_spaces
323324
}
324325

325326
#' Nest a flat parse table

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(

man/set_spaces.Rd

Lines changed: 2 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)