]> de.git.xonotic.org Git - xonotic/darkplaces.git/blobdiff - cvar.c
A minor removal of a few pieces of dead code. Nothing major. This is
[xonotic/darkplaces.git] / cvar.c
diff --git a/cvar.c b/cvar.c
index bee89d929f1aeaf6b7992ed7ac190cbbd846d9f1..152a86aee4f52446aa95dd683d5b5484acfb4b09 100644 (file)
--- a/cvar.c
+++ b/cvar.c
@@ -159,23 +159,28 @@ Cvar_CompleteBuildList (char *partial)
 Cvar_Set
 ============
 */
-void Cvar_Set (char *var_name, char *value)
+void Cvar_SetQuick (cvar_t *var, char *value)
 {
-       cvar_t  *var;
        qboolean changed;
 
-       var = Cvar_FindVar (var_name);
-       if (!var)
-       {       // there is an error in C code if this happens
-               Con_Printf ("Cvar_Set: variable %s not found\n", var_name);
+       if (var == NULL)
+       {
+               Con_Printf("Cvar_SetQuick: var == NULL\n");
                return;
        }
 
        changed = strcmp(var->string, value);
+       // LordHavoc: don't reallocate when there is no change
+       if (!changed)
+               return;
 
-       Z_Free (var->string);   // free the old value string
+       // LordHavoc: don't reallocate when the buffer is the same size
+       if (!var->string || strlen(var->string) != strlen(value))
+       {
+               Z_Free (var->string);   // free the old value string
 
-       var->string = Z_Malloc (strlen(value)+1);
+               var->string = Z_Malloc (strlen(value)+1);
+       }
        strcpy (var->string, value);
        var->value = atof (var->string);
        var->integer = (int) var->value;
@@ -186,11 +191,34 @@ void Cvar_Set (char *var_name, char *value)
        }
 }
 
+void Cvar_Set (char *var_name, char *value)
+{
+       cvar_t *var;
+       var = Cvar_FindVar (var_name);
+       if (var == NULL)
+       {
+               // there is an error in C code if this happens
+               Con_Printf ("Cvar_Set: variable %s not found\n", var_name);
+               return;
+       }
+
+       Cvar_SetQuick(var, value);
+}
+
 /*
 ============
 Cvar_SetValue
 ============
 */
+void Cvar_SetValueQuick (cvar_t *var, float value)
+{
+       char    val[32];
+
+       // LordHavoc: changed from %f to %g to use shortest representation
+       sprintf (val, "%g",value);
+       Cvar_SetQuick (var, val);
+}
+
 void Cvar_SetValue (char *var_name, float value)
 {
        char    val[32];
@@ -320,3 +348,4 @@ void Cvar_List_f (void)
        Con_Printf ("\n");
 }
 // 2000-01-09 CvarList command by Maddes
+