Skip to content

Commit

Permalink
Only generate the trace_back() as needed (#177)
Browse files Browse the repository at this point in the history
  • Loading branch information
DavisVaughan committed Nov 6, 2023
1 parent da5e39b commit 691afac
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 5 deletions.
3 changes: 3 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
# lifecycle (development version)

* Repeated calls to `deprecate_soft()` and `deprecate_warn()` are faster thanks
to some internal refactoring (#177).

* Switch from `expr_deparse()` to `deparse()`. This improves performance
considerably and the cost of making some unusual function calls mildly
less appealing (#167).
Expand Down
13 changes: 8 additions & 5 deletions R/deprecate.R
Original file line number Diff line number Diff line change
Expand Up @@ -115,13 +115,13 @@ deprecate_soft <- function(when,
default =
if (direct) {
always <- verbosity == "warning"
trace <- trace_back(bottom = caller_env())
trace_env <- caller_env()
deprecate_warn0(
msg,
id,
trace,
always = always,
direct = TRUE,
trace_env = trace_env,
user_env = user_env
)
},
Expand Down Expand Up @@ -157,13 +157,13 @@ deprecate_warn <- function(when,
default = {
direct <- is_direct(user_env)
always <- direct && (always || verbosity == "warning")
trace <- trace_back(bottom = caller_env())
trace_env <- caller_env()
deprecate_warn0(
msg,
id,
trace,
always = always,
direct = direct,
trace_env = trace_env,
user_env = user_env
)
},
Expand All @@ -188,10 +188,10 @@ deprecate_stop <- function(when,

deprecate_warn0 <- function(msg,
id = NULL,
trace = NULL,
always = FALSE,
direct = FALSE,
call = caller_env(),
trace_env = caller_env(),
user_env = caller_env(2)) {
id <- id %||% paste_line(msg)
if (!always && !needs_warning(id, call = call)) {
Expand Down Expand Up @@ -242,6 +242,9 @@ deprecate_warn0 <- function(msg,

footer
}

trace <- trace_back(bottom = trace_env)

wrn <- new_deprecated_warning(msg, trace, footer = footer)

# Record muffled warnings if testthat is running because it
Expand Down

0 comments on commit 691afac

Please sign in to comment.