Inline ecl_bds_push() and simplify ecl_symbol_slot(), which will never be called...
authorJuan Jose Garcia Ripoll <jjgarcia@jjgr-2.local>
Sat, 23 Jan 2010 00:35:17 +0000 (01:35 +0100)
committerJuan Jose Garcia Ripoll <jjgarcia@jjgr-2.local>
Sat, 23 Jan 2010 00:35:17 +0000 (01:35 +0100)
src/c/stacks.d
src/h/stacks.h

index d54e255..a0f2bdf 100644 (file)
@@ -138,9 +138,10 @@ ecl_extend_bindings_array(cl_object vector)
 }
 
 static cl_index
-ecl_bds_bind_special_case(cl_object s)
+ecl_bds_special_case(cl_object s)
 {
-        if (s->symbol.binding == ECL_MISSING_SPECIAL_BINDING) {
+        cl_index index = s->symbol.binding;
+        if (index == ECL_MISSING_SPECIAL_BINDING) {
                 return ecl_new_binding_index(s);
         } else {
                 cl_env_ptr env = ecl_process_env();
@@ -148,21 +149,16 @@ ecl_bds_bind_special_case(cl_object s)
                 env->bindings_array = ecl_extend_bindings_array(vector);
                 env->thread_local_bindings_size = vector->vector.dim;
                 env->thread_local_bindings = vector->vector.self.t;
-                return s->symbol.binding;
+                return index;
         }
 }
 
 void
-ecl_bds_bind(cl_env_ptr env, cl_object s, cl_object value)
+ecl_bds_bind_special_case(cl_env_ptr env, cl_object s, cl_object value)
 {
         cl_object *location;
         struct bds_bd *slot;
-        cl_index index = s->symbol.binding;
- AGAIN:
-        if (index >= env->thread_local_bindings_size) {
-                index = ecl_bds_bind_special_case(s);
-                goto AGAIN;
-        }
+        cl_index index = ecl_bds_special_case(s);
         location = env->thread_local_bindings + index;
         slot = ++env->bds_top;
         if (slot >= env->bds_limit) slot = ecl_bds_overflow();
@@ -179,7 +175,7 @@ ecl_bds_push(cl_env_ptr env, cl_object s)
         cl_index index = s->symbol.binding;
  AGAIN:
         if (index >= env->thread_local_bindings_size) {
-                index = ecl_bds_bind_special_case(s);
+                index = ecl_bds_special_case(s);
                 goto AGAIN;
         }
         location = env->thread_local_bindings + index;
@@ -202,17 +198,13 @@ ecl_bds_unwind1(cl_env_ptr env)
 cl_object *
 ecl_symbol_slot(cl_env_ptr env, cl_object s)
 {
-       if (Null(s)) {
-               return &(Cnil_symbol->symbol.value);
-        } else {
-                cl_index index = s->symbol.binding;
-                if (index < env->thread_local_bindings_size) {
-                        cl_object *location = env->thread_local_bindings + index;
-                        if (*location)
-                                return location;
-                }
-                return &s->symbol.value;
+        cl_index index = s->symbol.binding;
+        if (index < env->thread_local_bindings_size) {
+                cl_object *location = env->thread_local_bindings + index;
+                if (*location)
+                        return location;
         }
+        return &s->symbol.value;
 }
 
 cl_object
index 1a7edf3..22ce75f 100644 (file)
@@ -47,6 +47,24 @@ extern ECL_API struct bds_bd *ecl_bds_overflow(void) /*__attribute__((noreturn))
 #ifdef ECL_THREADS
 #define ECL_MISSING_SPECIAL_BINDING (~((cl_index)0))
 extern ECL_API void ecl_bds_bind(cl_env_ptr env, cl_object symbol, cl_object v);
+extern ECL_API void ecl_bds_bind_special_case(cl_env_ptr env,cl_object s, cl_object v);
+#define        ecl_bds_bind(env,sym,val) do {                                  \
+                const cl_env_ptr env_copy = (env);                      \
+                const cl_object s = (sym);                              \
+                const cl_object v = (val);                              \
+                cl_object *location;                                    \
+                struct bds_bd *slot;                                    \
+                const cl_index index = s->symbol.binding;               \
+                if (index >= env_copy->thread_local_bindings_size) {    \
+                        ecl_bds_bind_special_case(env_copy,s,v);        \
+                } else {                                                \
+                        location = env_copy->thread_local_bindings + index; \
+                        slot = ++env->bds_top;                          \
+                        if (slot >= env->bds_limit) slot = ecl_bds_overflow(); \
+                        slot->symbol = s;                               \
+                        slot->value = *location;                        \
+                        *location = v; }                                \
+        } while (0)
 extern ECL_API void ecl_bds_push(cl_env_ptr env, cl_object symbol);
 extern ECL_API void ecl_bds_unwind1(cl_env_ptr env);
 extern ECL_API cl_object *ecl_symbol_slot(cl_env_ptr env, cl_object s);