Skip to content

Commit 3319b13

Browse files
committed
Move R_BindingIsActive() before Rf_findVarInFrame3()
Because that triggers them
1 parent 20700ed commit 3319b13

File tree

1 file changed

+12
-3
lines changed

1 file changed

+12
-3
lines changed

src/main/envir.c

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -779,6 +779,18 @@ static SEXP R_GetGlobalCacheLoc(SEXP symbol)
779779
*/
780780

781781
R_BindingType R_GetBindingType(SEXP sym, SEXP env) {
782+
// We are currently getting the location in the environment twice:
783+
// - In `R_BindingIsActive()`
784+
// - In `Rf_findVarInFrame3()`
785+
// Ideally we'd do it once, which would require manually walking
786+
// over the environment frame / hashtable and get the location to
787+
// inspect.
788+
789+
// This check must be before `Rf_findVarInFrame3()` because that
790+
// forces active bindings
791+
if (R_BindingIsActive(sym, env))
792+
return R_BindingTypeActive;
793+
782794
SEXP value = Rf_findVarInFrame3(env, sym, FALSE);
783795

784796
if (value == R_UnboundValue)
@@ -794,9 +806,6 @@ R_BindingType R_GetBindingType(SEXP sym, SEXP env) {
794806
return R_BindingTypeDelayedPromise;
795807
}
796808

797-
if (R_BindingIsActive(sym, env))
798-
return R_BindingTypeActive;
799-
800809
return R_BindingTypeValue;
801810
}
802811

0 commit comments

Comments
 (0)