]> Nishi Git Mirror - serenade.git/commitdiff
optim
authornishi <nishi@0f02c867-ac3d-714e-8a88-971ba1f6efcf>
Sat, 27 Apr 2024 01:06:44 +0000 (01:06 +0000)
committernishi <nishi@0f02c867-ac3d-714e-8a88-971ba1f6efcf>
Sat, 27 Apr 2024 01:06:44 +0000 (01:06 +0000)
git-svn-id: file:///raid/svn-main/nishi-serenade/trunk@62 0f02c867-ac3d-714e-8a88-971ba1f6efcf

Serenade/interpreter.c

index a8adff36e6a03e1e36e268f269e75e3b14b592b8..f5a62f832a0da8f0fda8a8a2ef6dbd58831f9fae 100644 (file)
@@ -184,7 +184,7 @@ struct sn_interpreter_kv* sn_set_variable(struct sn_interpreter* sn, const char*
                sn->variables[i]->key = sn_strdup(name);
                sn->variables[i]->value = gen;
                sn->variables[i]->handler = NULL;
-               if(gen->type == SN_TYPE_FUNCTION) sn->variables[i]->handler = gen->handler;
+               if(gen != NULL && gen->type == SN_TYPE_FUNCTION) sn->variables[i]->handler = gen->handler;
                sn->variables[i + 1] = NULL;
                return sn->variables[i];
        }
@@ -201,19 +201,9 @@ struct sn_interpreter_kv* sn_set_handler(struct sn_interpreter* sn, const char*
                }
        }
        if(!replaced) {
-               struct sn_interpreter_kv** oldvariables = sn->variables;
-               for(i = 0; oldvariables[i] != NULL; i++)
-                       ;
-               sn->variables = malloc(sizeof(struct sn_interpreter_kv*) * (i + 2));
-               for(i = 0; oldvariables[i] != NULL; i++) {
-                       sn->variables[i] = oldvariables[i];
-               }
-               sn->variables[i] = malloc(sizeof(struct sn_generic));
-               sn->variables[i]->key = sn_strdup(name);
-               sn->variables[i]->value = NULL;
-               sn->variables[i]->handler = handler;
-               sn->variables[i + 1] = NULL;
-               return sn->variables[i];
+               struct sn_interpreter_kv* set = sn_set_variable(sn, name, NULL);
+               set->handler = handler;
+               return set;
        }
 }