Skip to content

Commit 042624e

Browse files
All internal instances of unlist() no longer preserve names to improve performance (@IndrajeetPatil, #998)
* Check if names need to preserved for `unlist()` * Change `two_cols_match()` not to use unlist * Remove `two_cols_match()` * Delete two_cols_match.Rd * pre-commit Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
1 parent 4049885 commit 042624e

File tree

10 files changed

+15
-41
lines changed

10 files changed

+15
-41
lines changed

NAMESPACE

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,6 @@ importFrom(purrr,flatten_int)
2929
importFrom(purrr,map)
3030
importFrom(purrr,map2)
3131
importFrom(purrr,map2_chr)
32-
importFrom(purrr,map2_lgl)
3332
importFrom(purrr,map_at)
3433
importFrom(purrr,map_chr)
3534
importFrom(purrr,map_int)

R/nest.R

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -114,8 +114,7 @@ drop_cached_children <- function(pd) {
114114
pos_ids_to_keep <- pd_parent_first %>%
115115
split(cumsum(pd_parent_first$parent == 0)) %>%
116116
map(find_pos_id_to_keep) %>%
117-
unlist() %>%
118-
unname()
117+
unlist(use.names = FALSE)
119118
pd[pd$pos_id %in% pos_ids_to_keep, ]
120119
} else {
121120
pd

R/parse.R

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -201,13 +201,15 @@ is_insufficiently_parsed_string <- function(pd) {
201201
is_insufficiently_parsed_number <- function(pd) {
202202
grepl("^0x", pd$text) & pd$token == "NUM_CONST"
203203
}
204-
#' @importFrom purrr map2_lgl
204+
205+
#' Check whether columns match
206+
#' @keywords internal
207+
#' @noRd
205208
lines_and_cols_match <- function(data) {
206209
left <- paste0(line_col_names(), "")
207210
right <- paste0(line_col_names(), "parent")
208-
map2_lgl(left, right,
209-
two_cols_match,
210-
data = data
211-
) %>%
212-
all()
211+
identical(
212+
unlist(data[left], use.names = FALSE),
213+
unlist(data[right], use.names = FALSE)
214+
)
213215
}

R/stylerignore.R

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ env_add_stylerignore <- function(pd_flat) {
2727
pd_flat_temp$pos_id, cumsum(is_stylerignore_switchpoint)
2828
) %>%
2929
map(~ rep(.x[1], length(.x))) %>%
30-
unlist()
30+
unlist(use.names = FALSE)
3131
pd_flat_temp$lag_newlines <- pd_flat_temp$lag_newlines
3232
pd_flat_temp$lag_spaces <- lag(pd_flat_temp$spaces, default = 0)
3333
is_terminal_to_ignore <- pd_flat_temp$terminal & pd_flat_temp$stylerignore

R/transform-block.R

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ parse_transform_serialize_r_block <- function(pd_nested,
4949
paste0(rep_char(" ", base_indention), pd_nested$text),
5050
~ c(rep("", .x), .y)
5151
) %>%
52-
unlist()
52+
unlist(use.names = FALSE)
5353
}
5454
c(rep("", start_line - 1), serialized_transformed_text)
5555
}

R/transform-files.R

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -257,7 +257,7 @@ parse_transform_serialize_r <- function(text,
257257
)
258258
}
259259

260-
text_out <- unlist(text_out)
260+
text_out <- unlist(text_out, use.names = FALSE)
261261

262262
verify_roundtrip(
263263
text, text_out,

R/utils-cache.R

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -180,7 +180,7 @@ cache_write <- function(text, transformers, more_specs) {
180180
file.create()
181181
}
182182

183-
styler_version <- unlist(unname(read.dcf("DESCRIPTION")[, "Version"]))
183+
styler_version <- unlist(unname(read.dcf("DESCRIPTION")[, "Version"]), use.names = FALSE)
184184

185185
cache_get_name <- function() {
186186
getOption("styler.cache_name")

R/utils-files.R

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ map_filetype_to_pattern <- function(filetype) {
5353
#' setdiff("./file.R", "file.R") # you want to standardize first.
5454
dir_without_. <- function(path, recursive = TRUE, ...) {
5555
purrr::map(path, dir_without_._one, recursive = recursive, ...) %>%
56-
unlist()
56+
unlist(use.names = FALSE)
5757
}
5858

5959
#' `dir()`, but with full names, ignored case, and included hidden files and

R/utils.R

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -36,16 +36,7 @@ convert_newlines_to_linebreaks <- function(text) {
3636
} else {
3737
.x
3838
}) %>%
39-
unlist()
40-
}
41-
42-
#' Check whether two columns match
43-
#'
44-
#' @param col1,col2 Column names as string.
45-
#' @param data The data frames that contains `col1` and `col2`.
46-
#' @keywords internal
47-
two_cols_match <- function(col1, col2, data) {
48-
all(unlist(data[col1]) == unlist(data[col2]))
39+
unlist(use.names = FALSE)
4940
}
5041

5142
odd_index <- function(x) {

man/two_cols_match.Rd

Lines changed: 0 additions & 17 deletions
This file was deleted.

0 commit comments

Comments
 (0)