Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve performance of tags functions #414

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 8 additions & 3 deletions R/tags.R
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,12 @@ nullOrEmpty <- function(x) {

# Given a vector or list, drop all the NULL or length-0 items in it
dropNullsOrEmpty <- function(x) {
x[!vapply(x, nullOrEmpty, FUN.VALUE=logical(1))]
ns <- lengths(x) == 0
Copy link
Collaborator

@cpsievert cpsievert Oct 16, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

From a quick look, it seems lengths() was added in R 3.2.0, so we'll want to put Depends: R (>= 3.2.0) in the DESCRIPTION (or whatever the appropriate version is)

Also, this change would mean nullOrEmpty no longer needs to exist (so please remove it)

if (any(ns)) {
x <- x[!ns]
}

x
}

isResolvedTag <- function(x) {
Expand Down Expand Up @@ -674,7 +679,6 @@ tags <- lapply(known_tags, function(tagname) {
new_function(
args = exprs(... = , .noWS = NULL, .renderHook = NULL),
expr({
validateNoWS(.noWS)
contents <- dots_list(...)
tag(!!tagname, contents, .noWS = .noWS, .renderHook = .renderHook)
}),
Expand Down Expand Up @@ -800,7 +804,8 @@ tag <- function(`_tag_name`, varArgs, .noWS = NULL, .renderHook = NULL) {
}

# Return tag data structure
structure(st, class = "shiny.tag")
class(st) <- "shiny.tag"
st
}

isTagList <- function(x) {
Expand Down