Skip to content

Commit

Permalink
Use minimal defer() instead of local_bindings() (#1093)
Browse files Browse the repository at this point in the history
Fixes #1089
  • Loading branch information
hadley authored Jul 27, 2023
1 parent 5efaa34 commit 1019107
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 8 deletions.
6 changes: 3 additions & 3 deletions DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,11 @@ BugReports: https://github.com/tidyverse/purrr/issues
Depends:
R (>= 3.5.0)
Imports:
cli (>= 3.4.0),
cli (>= 3.6.1),
lifecycle (>= 1.0.3),
magrittr (>= 1.5.0),
rlang (>= 0.4.10),
vctrs (>= 0.5.0)
rlang (>= 1.1.1),
vctrs (>= 0.6.3)
Suggests:
covr,
dplyr (>= 0.7.8),
Expand Down
3 changes: 3 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
# purrr (development version)

* Deprecation infrastructure in `map_chr()` now has much less overhead
leading to improved performance (#1089).

* purrr now requires R 3.5.0.

# purrr 1.0.1
Expand Down
18 changes: 13 additions & 5 deletions R/coerce.R
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,18 @@ deprecate_to_char <- function(type) {
)
}


# Can rewrite after https://github.com/r-lib/rlang/issues/1643
local_deprecation_user_env <- function(user_env = caller_env(2), frame = caller_env()) {
local_bindings(
deprecation_user_env = user_env,
.env = the,
.frame = frame
)

old <- the$deprecation_user_env
the$deprecation_user_env <- user_env
defer(the$deprecation_user_env <- old, frame)
}

# Lightweight equivalent of withr::defer()
defer <- function(expr, env = caller_env(), after = FALSE) {
thunk <- as.call(list(function() expr))
do.call(on.exit, list(thunk, TRUE, after), envir = env)
}

0 comments on commit 1019107

Please sign in to comment.