Skip to content

Commit

Permalink
perf: set use.names to false in unlist where applicable (#409)
Browse files Browse the repository at this point in the history
  • Loading branch information
m-muecke authored Aug 3, 2024
1 parent ab55290 commit 5978270
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 7 deletions.
2 changes: 1 addition & 1 deletion R/Design.R
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ Design = R6Class("Design",
# we need to make sure that every param has a (maybe empty) row in the graph table
fillin = data.table(id = ps$ids(), parents = list(character(0L)))
graph = rbind(graph, fillin[fillin$id %nin% graph$id, ])
graph = graph[, list("parents" = list(unlist(get("parents")))), by = "id"]
graph = graph[, list("parents" = list(unlist(get("parents"), use.names = FALSE))), by = "id"]
topo = topo_sort(graph)
pids_sorted = topo$id
storage_types = ps$storage_type
Expand Down
2 changes: 1 addition & 1 deletion R/Domain_methods.R
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,7 @@ check_domain_vectorize = function(ids, values, checker, more_args = list()) {
if (isTRUE(ch)) NULL else sprintf("%s: %s", id, ch)
})
}
errors = unlist(errors)
errors = unlist(errors, use.names = FALSE)
if (!length(errors)) return(TRUE)
str_collapse(errors, sep = "\n")
}
8 changes: 4 additions & 4 deletions R/ParamSet.R
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ ParamSet = R6Class("ParamSet",
# fastest way to init a data.table
private$.tags = structure(list(
id = rep(paramtbl$id, lengths(paramtbl$.tags)),
tag = unlist(paramtbl$.tags)
tag = unlist(paramtbl$.tags, use.names = FALSE)
), class = c("data.table", "data.frame")
)
} else {
Expand Down Expand Up @@ -542,7 +542,7 @@ ParamSet = R6Class("ParamSet",
}
msg
})
errors = unlist(errors)
errors = unlist(errors, use.names = FALSE)
if (!length(errors)) return(TRUE)
str_collapse(errors, sep = "\n")
},
Expand Down Expand Up @@ -816,7 +816,7 @@ ParamSet = R6Class("ParamSet",
deps = self$deps
if (nrow(deps)) { # add a nice extra charvec-col to the tab, which lists all parents-ids
on = NULL
dd = deps[, list(parents = list(unlist(on))), by = "id"]
dd = deps[, list(parents = list(unlist(on, use.names = FALSE))), by = "id"]
d = merge(d, dd, by = "id", all.x = TRUE)
}
v = named_list(d$id) # add values to last col of print-dt as list col
Expand Down Expand Up @@ -863,7 +863,7 @@ ParamSet = R6Class("ParamSet",
assert_list(v, any.missing = FALSE, types = "character")
if (length(v)) assert_names(names(v), permutation.of = private$.params$id)
# as.character() to handle empty lists and resulting NULL-valures.
private$.tags = data.table(id = rep(as.character(names(v)), map_int(v, length)), tag = as.character(unlist(v)), key = "id")
private$.tags = data.table(id = rep(as.character(names(v)), map_int(v, length)), tag = as.character(unlist(v, use.names = FALSE)), key = "id")
setindexv(private$.tags, "tag")
# return value with original ordering
return(v)
Expand Down
2 changes: 1 addition & 1 deletion R/ParamSetCollection.R
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@ ParamSetCollection = R6Class("ParamSetCollection", inherit = ParamSet,
}
if (tag_sets && n != "") paramtbl[, .tags := map(.tags, function(x) c(x, sprintf("set_%s", n)))]
if (tag_params) paramtbl[, .tags := pmap(list(.tags, original_id), function(x, n) c(x, sprintf("param_%s", n)))]
newtags = paramtbl[, .(tag = unique(unlist(.tags))), by = "id"]
newtags = paramtbl[, .(tag = unique(unlist(.tags, use.names = FALSE))), by = "id"]
if (nrow(newtags)) {
private$.tags = setkeyv(rbind(private$.tags, newtags), "id")
}
Expand Down

0 comments on commit 5978270

Please sign in to comment.