Skip to content

Commit

Permalink
list is so much faster than lst
Browse files Browse the repository at this point in the history
  • Loading branch information
lorenzwalthert committed Jan 24, 2021
1 parent 7dac9eb commit 62ebd4b
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 50 deletions.
94 changes: 47 additions & 47 deletions R/style-guides.R
Original file line number Diff line number Diff line change
Expand Up @@ -74,9 +74,9 @@ tidyverse_style <- function(scope = "tokens",


indention_manipulators <- if ("indention" %in% scope) {
lst(
list(
indent_braces = partial(indent_braces, indent_by = indent_by),
unindent_fun_dec,
unindent_fun_dec = unindent_fun_dec,
indent_op = partial(indent_op, indent_by = indent_by),
indent_eq_sub = partial(indent_eq_sub, indent_by = indent_by),
indent_without_paren = partial(indent_without_paren,
Expand All @@ -86,11 +86,11 @@ tidyverse_style <- function(scope = "tokens",
)
}
space_manipulators <- if ("spaces" %in% scope) {
lst(
remove_space_before_closing_paren,
list(
remove_space_before_closing_paren = remove_space_before_closing_paren,
remove_space_before_opening_paren = if (strict) remove_space_before_opening_paren,
add_space_after_for_if_while,
remove_space_before_comma,
add_space_after_for_if_while = add_space_after_for_if_while,
remove_space_before_comma = remove_space_before_comma,
style_space_around_math_token = partial(
style_space_around_math_token, strict,
math_token_spacing$zero,
Expand All @@ -103,34 +103,34 @@ tidyverse_style <- function(scope = "tokens",
spacing_around_op = purrr::partial(set_space_around_op,
strict = strict
),
remove_space_after_opening_paren,
remove_space_after_excl,
set_space_after_bang_bang,
remove_space_before_dollar,
remove_space_after_fun_dec,
remove_space_around_colons,
remove_space_after_opening_paren = remove_space_after_opening_paren,
remove_space_after_excl = remove_space_after_excl,
set_space_after_bang_bang = set_space_after_bang_bang,
remove_space_before_dollar = remove_space_before_dollar,
remove_space_after_fun_dec = remove_space_after_fun_dec,
remove_space_around_colons = remove_space_around_colons,
start_comments_with_space = partial(start_comments_with_space,
force_one = start_comments_with_one_space
),
remove_space_after_unary_pm_nested,
remove_space_after_unary_pm_nested = remove_space_after_unary_pm_nested,
spacing_before_comments = if (strict) {
set_space_before_comments
} else {
add_space_before_comments
},
set_space_between_levels,
set_space_between_eq_sub_and_comma,
set_space_in_curly_curly
set_space_between_levels = set_space_between_levels,
set_space_between_eq_sub_and_comma = set_space_between_eq_sub_and_comma,
set_space_in_curly_curly = set_space_in_curly_curly
)
}

use_raw_indention <- !("indention" %in% scope)

line_break_manipulators <- if ("line_breaks" %in% scope) {
lst(
set_line_break_around_comma_and_or,
set_line_break_after_assignment,
set_line_break_before_curly_opening,
list(
set_line_break_around_comma_and_or = set_line_break_around_comma_and_or,
set_line_break_after_assignment = set_line_break_after_assignment,
set_line_break_before_curly_opening = set_line_break_before_curly_opening,
remove_line_break_before_round_closing_after_curly =
if (strict) remove_line_break_before_round_closing_after_curly,
remove_line_breaks_in_fun_dec =
Expand All @@ -141,7 +141,7 @@ tidyverse_style <- function(scope = "tokens",
),
# must be after style_line_break_around_curly as it remove line
# breaks again for {{.
set_line_break_around_curly_curly,
set_line_break_around_curly_curly = set_line_break_around_curly_curly,
set_line_break_after_opening_if_call_is_multi_line = if (strict) {
partial(
set_line_break_after_opening_if_call_is_multi_line,
Expand All @@ -162,12 +162,12 @@ tidyverse_style <- function(scope = "tokens",
}

token_manipulators <- if ("tokens" %in% scope) {
lst(
fix_quotes,
force_assignment_op,
resolve_semicolon,
add_brackets_in_pipe,
remove_terminal_token_before_and_after,
list(
fix_quotes = fix_quotes,
force_assignment_op = force_assignment_op,
resolve_semicolon = resolve_semicolon,
add_brackets_in_pipe = add_brackets_in_pipe,
remove_terminal_token_before_and_after = remove_terminal_token_before_and_after,
wrap_if_else_while_for_fun_multi_line_in_curly =
if (strict) wrap_if_else_while_for_fun_multi_line_in_curly
)
Expand Down Expand Up @@ -311,20 +311,20 @@ create_style_guide <- function(initialize = default_style_guide_attributes,
style_guide_version = NULL,
more_specs_style_guide = NULL,
transformers_drop = specify_transformer_dropping()) {
lst(
list(
# transformer functions
initialize = lst(initialize),
line_break,
space,
token,
indention,
initialize = list(initialize = initialize),
line_break = line_break,
space = space,
token = token,
indention = indention,
# transformer options
use_raw_indention,
reindention,
style_guide_name,
style_guide_version,
more_specs_style_guide,
transformers_drop
use_raw_indention = use_raw_indention,
reindention = reindention,
style_guide_name = style_guide_name,
style_guide_version = style_guide_version,
more_specs_style_guide = more_specs_style_guide,
transformers_drop = transformers_drop
) %>%
map(compact)
}
Expand Down Expand Up @@ -383,8 +383,8 @@ specify_transformer_dropping <- function(spaces = NULL,
indention = NULL,
line_breaks = NULL,
tokens = NULL) {
lst(
space = spaces, indention, line_break = line_breaks,
list(
space = spaces, indention = indention, line_break = line_breaks,
token = tokens
)
}
Expand Down Expand Up @@ -415,10 +415,10 @@ NULL
specify_reindention <- function(regex_pattern = NULL,
indention = 0,
comments_only = TRUE) {
lst(
regex_pattern,
indention,
comments_only
list(
regex_pattern = regex_pattern,
indention = indention,
comments_only = comments_only
)
}

Expand Down Expand Up @@ -494,9 +494,9 @@ specify_math_token_spacing <-
function(zero = "'^'",
one = c("'+'", "'-'", "'*'", "'/'")) {
assert_tokens(c(one, zero))
lst(
list(
one = setdiff(c(math_token, one), zero),
zero
zero = zero
)
}

Expand Down
2 changes: 1 addition & 1 deletion R/transform-code.R
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ separate_chunks <- function(lines, filetype) {
c(1, r_raw_chunks$ends), c(r_raw_chunks$starts, length(lines)),
~ lines[seq2(.x, .y)]
)
lst(r_chunks, text_chunks)
list(r_chunks = r_chunks, text_chunks = text_chunks)
}

#' Identifies raw Rmd or Rnw code chunks
Expand Down
4 changes: 2 additions & 2 deletions R/transform-files.R
Original file line number Diff line number Diff line change
Expand Up @@ -187,15 +187,15 @@ parse_transform_serialize_roxygen <- function(text, transformers, base_indention
#' @keywords internal
split_roxygen_segments <- function(text, roxygen_examples) {
if (is.null(roxygen_examples)) {
return(lst(separated = list(text), selectors = NULL))
return(list(separated = list(text), selectors = NULL))
}
all_lines <- seq2(1L, length(text))
active_segment <- as.integer(all_lines %in% roxygen_examples)
segment_id <- cumsum(abs(c(0L, diff(active_segment)))) + 1L
separated <- split(text, factor(segment_id))
restyle_selector <- ifelse(roxygen_examples[1] == 1L, odd_index, even_index)

lst(separated, selectors = restyle_selector(separated))
list(separated = separated, selectors = restyle_selector(separated))
}

#' Parse, transform and serialize text
Expand Down

0 comments on commit 62ebd4b

Please sign in to comment.