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

cache the 'are we on Windows' test (closes #137) #138

Merged
merged 1 commit into from
Dec 4, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
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
6 changes: 6 additions & 0 deletions ChangeLog
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
2019-12-04 Dirk Eddelbuettel <edd@debian.org>

* R/init.R (.onLoad): Cache isWindows state
(.isWindows): Return cached value
* R/digest.R (digest): Use cached value accessor

2019-11-23 Dirk Eddelbuettel <edd@debian.org>

* inst/tinytest/test_new_matrix_behaviour.R: Split off tests affected
Expand Down
4 changes: 1 addition & 3 deletions R/digest.R
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,6 @@ digest <- function(object, algo=c("md5", "sha1", "crc32", "sha256", "sha512",
algo <- match.arg(algo)
errormode <- match.arg(errormode)

isWindows <- Sys.info()[["sysname"]] == "Windows"

if (is.infinite(length)) {
length <- -1 # internally we use -1 for infinite len
}
Expand Down Expand Up @@ -93,7 +91,7 @@ digest <- function(object, algo=c("md5", "sha1", "crc32", "sha256", "sha512",
if (file) {
algoint <- algoint+100
object <- path.expand(object)
if (isWindows) object <- enc2utf8(object)
if (.isWindows()) object <- enc2utf8(object)
check_file(object, errormode)
}
## if skip is auto (or any other text for that matter), we just turn it
Expand Down
17 changes: 12 additions & 5 deletions R/init.R
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@

## digest -- hash digest functions for R
##
## Copyright (C) 2003 - 2017 Dirk Eddelbuettel <edd@debian.org>
## Copyright (C) 2003 - 2019 Dirk Eddelbuettel <edd@debian.org>
##
## This file is part of digest.
##
Expand All @@ -22,12 +22,14 @@

.onLoad <- function(libname, pkgname) {
## we set a default level of two, with a possible override
.pkgenv[["serializeVersion"]] <- getOption("serializeVersion", 2L) # #nocov
.pkgenv[["serializeVersion"]] <- getOption("serializeVersion", 2L) # #nocov start
## allow old crc32 behaviour
.pkgenv[["crc32Preference"]] <- getOption("digestOldCRC32Format", FALSE) # #nocov
.pkgenv[["crc32Preference"]] <- getOption("digestOldCRC32Format", FALSE)
## allow version specific sha1 behaviour
.pkgenv[["sha1PackageVersion"]] <- getOption("sha1PackageVersion", # #nocov
packageVersion("digest")) # #nocov
.pkgenv[["sha1PackageVersion"]] <- getOption("sha1PackageVersion",
packageVersion("digest"))
## cache if we are on Windows as the call is a little expensive (GH issue #137)
.pkgenv[["isWindows"]] <- Sys.info()[["sysname"]] == "Windows"
}

.getSerializeVersion <- function() {
Expand All @@ -49,3 +51,8 @@
getOption("sha1PackageVersion", .pkgenv[["sha1PackageVersion"]])
)
}

.isWindows <- function() {
## return the cached value of Sys.info()[["sysname"]] == "Windows"
.pkgenv[["isWindows"]]
}