summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndy Wingo <wingo@pobox.com>2010-09-02 20:48:08 -0700
committerAndy Wingo <wingo@pobox.com>2010-09-02 21:31:55 -0700
commit3be872798395b745ee693a2975900a81980037d2 (patch)
tree0b4d4da3889a2c72e4844767847511cdc8f88347
parentf57fdf07d6374028f35bcb1ee748a94022deda6d (diff)
downloadguile-3be872798395b745ee693a2975900a81980037d2.tar.gz
module-local-variable optimization
* libguile/modules.c (scm_module_local_variable): An optimization in the common no-module-binder case.
-rw-r--r--libguile/modules.c29
1 files changed, 22 insertions, 7 deletions
diff --git a/libguile/modules.c b/libguile/modules.c
index a0c47f2db..6c3d0e8b6 100644
--- a/libguile/modules.c
+++ b/libguile/modules.c
@@ -412,19 +412,34 @@ SCM_DEFINE (scm_module_local_variable, "module-local-variable", 2, 0, 0,
if (SCM_BOUND_THING_P (b))
return b;
- /* 2. Search imported bindings. In order to be consistent with
- `module-variable', the binder gets called only when no imported binding
- matches SYM. */
- b = module_imported_variable (module, sym);
- if (SCM_BOUND_THING_P (b))
- return SCM_BOOL_F;
+ /* At this point we should just be able to return #f, but there is the
+ possibility that a custom binder establishes a mapping for this
+ variable.
+
+ However a custom binder should be called only if there is no
+ imported binding with the name SYM. So here instead of the order:
+
+ 2. Search imported bindings. In order to be consistent with
+ `module-variable', the binder gets called only when no
+ imported binding matches SYM.
+
+ 3. Query the custom binder.
+
+ we first check if there is a binder at all, and if not, just return
+ #f directly.
+ */
{
- /* 3. Query the custom binder. */
SCM binder = SCM_MODULE_BINDER (module);
if (scm_is_true (binder))
{
+ /* 2. */
+ b = module_imported_variable (module, sym);
+ if (SCM_BOUND_THING_P (b))
+ return SCM_BOOL_F;
+
+ /* 3. */
b = scm_call_3 (binder, module, sym, SCM_BOOL_F);
if (SCM_BOUND_THING_P (b))
return b;