From 5924a612d74e878ec353030e8c61842e56947076 Mon Sep 17 00:00:00 2001 From: Maximilian Muecke Date: Thu, 3 Oct 2024 18:58:58 +0200 Subject: [PATCH] perf: add missing fixed for fixed strings --- R/aaa-utils.R | 2 +- R/aab-rstudio-detect.R | 2 +- R/ansi-hyperlink.R | 2 +- R/assertions.R | 2 +- R/cliapp.R | 6 +++--- R/glue.R | 2 +- R/hash.R | 4 ++-- R/internals.R | 2 +- R/num-ansi-colors.R | 2 +- R/prettycode.R | 8 ++++---- R/simple-theme.R | 2 +- R/themes.R | 2 +- R/vt.R | 14 +++++++------- exec/up.R | 2 +- tools/get-rstudio-themes.R | 2 +- tools/spinners.R | 8 ++++---- 16 files changed, 31 insertions(+), 31 deletions(-) diff --git a/R/aaa-utils.R b/R/aaa-utils.R index 752494bd3..e41e7587b 100644 --- a/R/aaa-utils.R +++ b/R/aaa-utils.R @@ -85,7 +85,7 @@ tail_na <- function(x, n = 1) { } dedent <- function(x, n = 2) { - first_n_char <- strsplit(ansi_substr(x, 1, n), "")[[1]] + first_n_char <- strsplit(ansi_substr(x, 1, n), "", fixed = TRUE)[[1]] n_space <- cumsum(first_n_char == " ") d_n_space <- diff(c(0, n_space)) first_not_space <- utils::head(c(which(d_n_space == 0), n + 1), 1) diff --git a/R/aab-rstudio-detect.R b/R/aab-rstudio-detect.R index 8942089c3..3bd329bd9 100644 --- a/R/aab-rstudio-detect.R +++ b/R/aab-rstudio-detect.R @@ -164,7 +164,7 @@ rstudio <- local({ "rstudio_build_pane" } else if (new$envs[["RSTUDIOAPI_IPC_REQUESTS_FILE"]] != "" && - grepl("rstudio", new$envs[["XPC_SERVICE_NAME"]])) { + grepl("rstudio", new$envs[["XPC_SERVICE_NAME"]], fixed = TRUE)) { # RStudio job, XPC_SERVICE_NAME=0 in the subprocess of a job # process. Hopefully this is reliable. "rstudio_job" diff --git a/R/ansi-hyperlink.R b/R/ansi-hyperlink.R index 1a5035705..6dfe26866 100644 --- a/R/ansi-hyperlink.R +++ b/R/ansi-hyperlink.R @@ -124,7 +124,7 @@ abs_path1 <- function(x) { # -- {.fun} --------------------------------------------------------------- make_link_fun <- function(txt) { - tolink <- grepl("::", txt) + tolink <- grepl("::", txt, fixed = TRUE) linked <- grepl("\007|\033\\\\", txt) todo <- tolink & !linked if (!any(todo)) return(txt) diff --git a/R/assertions.R b/R/assertions.R index c8c876c83..0e4209a32 100644 --- a/R/assertions.R +++ b/R/assertions.R @@ -12,7 +12,7 @@ is_border_style <- function(x) { } is_padding_or_margin <- function(x) { - is.numeric(x) && length(x) %in% c(1, 4) && all(!is.na(x)) && + is.numeric(x) && length(x) %in% c(1, 4) && !anyNA(x) && all(as.integer(x) == x) } diff --git a/R/cliapp.R b/R/cliapp.R index 9d985afa1..5db0b0a05 100644 --- a/R/cliapp.R +++ b/R/cliapp.R @@ -257,8 +257,8 @@ clii_alert <- function(app, type, text, id, class, wrap) { style <- app$get_current_style() before <- call_if_fun(style$before) %||% "" after <- call_if_fun(style$after) %||% "" - before <- gsub(" ", "\u00a0", before) - after <- gsub(" ", "\u00a0", after) + before <- gsub(" ", "\u00a0", before, fixed = TRUE) + after <- gsub(" ", "\u00a0", after, fixed = TRUE) text[1] <- paste0(before, text[1]) text[length(text)] <- paste0(text[length(text)], after) if (is.function(style$fmt)) text <- style$fmt(text) @@ -277,7 +277,7 @@ clii_bullets <- function(app, text, id, class) { length(nms) <- length(text) nms[is.na(nms) | nms == ""] <- "empty" nms[nms == " "] <- "space" - nms <- gsub(" ", "-", nms) + nms <- gsub(" ", "-", nms, fixed = TRUE) # cls is vectorized here (!) cls <- paste0("bullet memo-item bullet-", nms, " memo-item=", nms) diff --git a/R/glue.R b/R/glue.R index 80aba0253..b8f08572b 100644 --- a/R/glue.R +++ b/R/glue.R @@ -159,7 +159,7 @@ collapse_head <- function(x, sep, sep2, last, trunc, width, ellipsis) { # special cases that do not need trimming if (lnx == 0L) { return("") - } else if (any(is.na(x))) { + } else if (anyNA(x)) { return(NA_character_) } diff --git a/R/hash.R b/R/hash.R index d2c7b7253..fb5c884be 100644 --- a/R/hash.R +++ b/R/hash.R @@ -301,7 +301,7 @@ hash_emoji1 <- function(x, size = 3) { hash_emoji1_transform <- function(md5, size) { md513 <- substr(md5, 1, 13) - mdint <- as.integer(as.hexmode(strsplit(md513, "")[[1]])) + mdint <- as.integer(as.hexmode(strsplit(md513, "", fixed = TRUE)[[1]])) hash <- sum(mdint * 16^(0:12)) base <- nrow(emojis) @@ -444,7 +444,7 @@ hash_animal1 <- function(x, n_adj = 2) { hash_animal1_transform <- function(md5, n_adj) { md513 <- substr(md5, 1, 13) - mdint <- as.integer(as.hexmode(strsplit(md513, "")[[1]])) + mdint <- as.integer(as.hexmode(strsplit(md513, "", fixed = TRUE)[[1]])) hash <- sum(mdint * 16^(0:12)) len_ani <- length(gfycat_animals) diff --git a/R/internals.R b/R/internals.R index 754346570..2436645ce 100644 --- a/R/internals.R +++ b/R/internals.R @@ -8,7 +8,7 @@ clii__xtext <- function(app, text, .list, indent, padding, ln = TRUE, wrap = TRU text <- app$inline(text, .list = .list) exdent <- style$`text-exdent` %||% 0L - esc <- function(x) gsub(" ", "\u00a0", x) + esc <- function(x) gsub(" ", "\u00a0", x, fixed = TRUE) bef <- call_if_fun(style$before) if (!is.null(bef)) text[1] <- paste0(esc(bef), text[1]) diff --git a/R/num-ansi-colors.R b/R/num-ansi-colors.R index 1263ba149..716eb04e1 100644 --- a/R/num-ansi-colors.R +++ b/R/num-ansi-colors.R @@ -309,7 +309,7 @@ emacs_version <- function() { ver <- Sys.getenv("INSIDE_EMACS") if (ver == "") return(NA_integer_) - ver <- gsub("'", "", ver) + ver <- gsub("'", "", ver, fixed = TRUE) ver <- strsplit(ver, ",", fixed = TRUE)[[1]] ver <- strsplit(ver, ".", fixed = TRUE)[[1]] diff --git a/R/prettycode.R b/R/prettycode.R index 7c695efbc..950d6c735 100644 --- a/R/prettycode.R +++ b/R/prettycode.R @@ -261,7 +261,7 @@ code_theme_make <- function(theme) { if (is.list(theme)) return(theme) if (is_string(theme)) { if (theme %in% names(rstudio_themes)) return(rstudio_themes[[theme]]) - lcs <- gsub(" ", "_", tolower(names(rstudio_themes))) + lcs <- gsub(" ", "_", tolower(names(rstudio_themes)), fixed = TRUE) if (theme %in% lcs) return(rstudio_themes[[ match(theme, lcs)[1] ]]) warning("Unknown cli code theme: `", theme, "`.") return(NULL) @@ -412,13 +412,13 @@ find_function_symbol <- function(name, envir = .GlobalEnv) { while (!identical(envir, empty)) { if (exists(name, envir = envir, inherits = FALSE, mode = "function")) { env_name <- environmentName(envir) - if (grepl("package:", env_name)) { + if (grepl("package:", env_name, fixed = TRUE)) { env_name <- sub("^package:", "", env_name) } - if (grepl("imports:", env_name)) { + if (grepl("imports:", env_name, fixed = TRUE)) { env_name <- environmentName(environment(get(name, envir))) } - if (grepl("package:", env_name)) { + if (grepl("package:", env_name, fixed = TRUE)) { env_name <- sub("^package:", "", env_name) } if (env_name %in% c("", "R_GlobalEnv")) { diff --git a/R/simple-theme.R b/R/simple-theme.R index 5311d1cb1..9928e2091 100644 --- a/R/simple-theme.R +++ b/R/simple-theme.R @@ -194,7 +194,7 @@ is_iterm_dark <- function() { stdout = TRUE, stderr = TRUE )) - nums <- scan(text = gsub(",", "", out), quiet = TRUE) + nums <- scan(text = gsub(",", "", out, fixed = TRUE), quiet = TRUE) mean(nums) < 20000 }) } diff --git a/R/themes.R b/R/themes.R index 13ac510b7..70397a022 100644 --- a/R/themes.R +++ b/R/themes.R @@ -261,7 +261,7 @@ encode_string <- function(x) { } quote_weird_name0 <- function(x) { - x <- gsub(" ", "\u00a0", x) + x <- gsub(" ", "\u00a0", x, fixed = TRUE) x2 <- ansi_strip(x) fc <- first_character(x2) diff --git a/R/vt.R b/R/vt.R index 98ea7fdee..2ebaedfbb 100644 --- a/R/vt.R +++ b/R/vt.R @@ -79,13 +79,13 @@ vt_output <- function(output, width = 80L, height = 25L) { lineno = i, segmentno = seq_along(segments), segment = segs, - bold = grepl("bold;", lgs$values), - italic = grepl("italic;", lgs$values), - underline = grepl("underline;", lgs$values), - strikethrough = grepl("strikethrough;", lgs$values), - blink = grepl("blink;", lgs$values), - inverse = grepl("inverse;", lgs$values), - color= fg, + bold = grepl("bold;", lgs$values, fixed = TRUE), + italic = grepl("italic;", lgs$values, fixed = TRUE), + underline = grepl("underline;", lgs$values, fixed = TRUE), + strikethrough = grepl("strikethrough;", lgs$values, fixed = TRUE), + blink = grepl("blink;", lgs$values, fixed = TRUE), + inverse = grepl("inverse;", lgs$values, fixed = TRUE), + color = fg, background_color = bg, link = link, link_params = link_params diff --git a/exec/up.R b/exec/up.R index 4a532154e..3f8f33367 100755 --- a/exec/up.R +++ b/exec/up.R @@ -32,7 +32,7 @@ up <- function(urls, timeout = 5) { } })$ catch(error = function(err) { - e <- if (grepl("timed out", err$message)) "timed out" else "error" + e <- if (grepl("timed out", err$message, fixed = TRUE)) "timed out" else "error" cli_alert_danger("{.url {url}} ({e})") }) }) diff --git a/tools/get-rstudio-themes.R b/tools/get-rstudio-themes.R index 304fe6dd9..d87541d8c 100644 --- a/tools/get-rstudio-themes.R +++ b/tools/get-rstudio-themes.R @@ -97,7 +97,7 @@ rstudio_css <- function(theme) { ## Three digit colors are not handled by cli... if (grepl("^#[0-9a-fA-F][0-9a-fA-F][0-9a-fA-F]$", col)) { - col <- paste(rep(strsplit(col, "")[[1]], c(1, 2, 2, 2)), collapse = "") + col <- paste(rep(strsplit(col, "", fixed = TRUE)[[1]], c(1, 2, 2, 2)), collapse = "") } ## rgb () form if (grepl("^rgb", col)) { diff --git a/tools/spinners.R b/tools/spinners.R index 2bbde719a..889fc6fd7 100644 --- a/tools/spinners.R +++ b/tools/spinners.R @@ -9,8 +9,8 @@ spinners <- pdt[, c("name", "interval", "frames")] usethis::use_data(spinners, internal = TRUE) spinners <- rbind( spinners, - list(name = "growVeriticalDotsLR", interval = 80, frames = strsplit("⠀⡀⣀⣄⣤⣦⣶⣷⣿⣾⣶⣴⣤⣠⣀⢀", "")), - list(name = "growVeriticalDotsRL", interval = 80, frames = strsplit("⠀⢀⣀⣠⣤⣴⣶⣾⣿⣷⣶⣦⣤⣄⣀⡀", "")), - list(name = "growVeriticalDotsLL", interval = 80, frames = strsplit("⠀⡀⣀⣄⣤⣦⣶⣷⣿⣷⣶⣦⣤⣄⣀⡀", "")), - list(name = "growVeriticalDotsRR", interval = 80, frames = strsplit("⠀⡀⣀⣠⣤⣴⣶⣾⣿⣾⣶⣴⣤⣠⣀⢀", "")) + list(name = "growVeriticalDotsLR", interval = 80, frames = strsplit("⠀⡀⣀⣄⣤⣦⣶⣷⣿⣾⣶⣴⣤⣠⣀⢀", "", fixed = TRUE)), + list(name = "growVeriticalDotsRL", interval = 80, frames = strsplit("⠀⢀⣀⣠⣤⣴⣶⣾⣿⣷⣶⣦⣤⣄⣀⡀", "", fixed = TRUE)), + list(name = "growVeriticalDotsLL", interval = 80, frames = strsplit("⠀⡀⣀⣄⣤⣦⣶⣷⣿⣷⣶⣦⣤⣄⣀⡀", "", fixed = TRUE)), + list(name = "growVeriticalDotsRR", interval = 80, frames = strsplit("⠀⡀⣀⣠⣤⣴⣶⣾⣿⣾⣶⣴⣤⣠⣀⢀", "", fixed = TRUE)) )