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 short-circuit logic #73

Open
flying-sheep opened this issue Jul 13, 2016 · 3 comments
Open

improve short-circuit logic #73

flying-sheep opened this issue Jul 13, 2016 · 3 comments

Comments

@flying-sheep
Copy link
Member

i just checked the code of capabilities(), and what @randy3k did in #62 is probably not that fast after all. this is the code:

capabilities <- function (what = NULL) {
    z <- .Internal(capabilities())
    if (!is.null(what)) 
        z <- z[match(what, names(z), 0L)]
    if (.Platform$OS.type == 'windows') 
        return(z)
    nas <- names(z[is.na(z)])
    if (any(nas %in% c('X11', 'jpeg', 'png', 'tiff'))) {
        z[nas] <- tryCatch(.Internal(capabilitiesX11()), error = function(e) FALSE)
    }
    z
}

so there are 1-2 internal calls:

  1. .Internal(capabilities())
  2. .Internal(capabilitiesX11()) (if any(nas %in% c('X11', 'jpeg', 'png', 'tiff')))
@randy3k
Copy link
Contributor

randy3k commented Jul 13, 2016

Perhaps, just separate the X11 and non-X11 checking.

@jankatins
Copy link
Contributor

Yea, first all non-X11 in one go, then X11...

BTW: why don't we do the checks on startup instead of each time? the only problem I can think of is when user installs something during the session and things like check_capability('png') can't be changed from within the session, as all these are compiled into R, aren't they?

@flying-sheep
Copy link
Member Author

We could do it on startup, but we'll have to use an environment I think. In .onLoad I think?

Simply assigning to a variable at top level happens at compile time, so the check would return whatever capabilities the building system had at build time.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants