Skip to content

Commit

Permalink
optimize loops and access
Browse files Browse the repository at this point in the history
  • Loading branch information
wlandau committed Jan 6, 2025
1 parent f9997c3 commit 6b8399b
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 10 deletions.
16 changes: 8 additions & 8 deletions R/class_counter.R
Original file line number Diff line number Diff line change
Expand Up @@ -33,14 +33,14 @@ counter_exists_name <- function(counter, name) {

counter_exist_names <- function(counter, names) {
envir <- .subset2(counter, "envir")
as.logical(
lapply(
names,
function(name) {
!is.null(envir[[name]])
}
)
)
n <- length(names)
missing <- logical(length = n)
index <- 1L
while (index <= n) {
missing[index] <- is.null(.subset2(envir, .subset(names, index)))
index <- index + 1L
}
!missing
}

counter_filter_exists <- function(counter, names) {
Expand Down
5 changes: 3 additions & 2 deletions R/utils_files.R
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,11 @@ dir_create_runtime <- function(x) {
}

file_exists_runtime <- function(x) {
if (is.null(tar_runtime$file_exist)) {
file_exist <- .subset2(tar_runtime, "file_exist")
if (is.null(file_exist)) {
return(file.exists(x))
}
out <- counter_exist_names(tar_runtime$file_exist, x)
out <- counter_exist_names(file_exist, x)
out[!out] <- file.exists(x[!out])
out
}
Expand Down

0 comments on commit 6b8399b

Please sign in to comment.