<html><head><meta name="color-scheme" content="light dark"></head><body><pre style="word-wrap: break-word; white-space: pre-wrap;">[PATCH] STree_InsertAlloc API change

The option of having the node supplied by the caller wasn't ever being used,
so removed. However, there are cases where it's not necessary to duplicate the
string, so add an option for that. All callers updated.

diff -urN a/NQ/common.c head/NQ/common.c
--- a/NQ/common.c	2006-02-19 12:33:24.000000000 +1030
+++ head/NQ/common.c	2006-02-25 10:04:54.000000000 +1030
@@ -1338,7 +1338,7 @@
 	    if (fname) {
 		strncpy(fname, d-&gt;d_name, len);
 		fname[len] = '\0';
-		STree_InsertAlloc(root, fname, NULL);
+		STree_InsertAlloc(root, fname, true);
 		Z_Free(fname);
 	    }
 	}
@@ -1371,7 +1371,7 @@
 	    if (fname) {
 		strncpy(fname, pak_f, len);
 		fname[len] = '\0';
-		STree_InsertAlloc(root, fname, NULL);
+		STree_InsertAlloc(root, fname, true);
 		Z_Free(fname);
 	    }
 	}
diff -urN a/QW/common/common.c head/QW/common/common.c
--- a/QW/common/common.c	2006-02-19 12:33:24.000000000 +1030
+++ head/QW/common/common.c	2006-02-25 10:05:16.000000000 +1030
@@ -1426,7 +1426,7 @@
 	    if (fname) {
 		strncpy(fname, d-&gt;d_name, len);
 		fname[len] = '\0';
-		STree_InsertAlloc(root, fname, NULL);
+		STree_InsertAlloc(root, fname, true);
 		Z_Free(fname);
 	    }
 	}
@@ -1459,7 +1459,7 @@
 	    if (fname) {
 		strncpy(fname, pak_f, len);
 		fname[len] = '\0';
-		STree_InsertAlloc(root, fname, NULL);
+		STree_InsertAlloc(root, fname, true);
 		Z_Free(fname);
 	    }
 	}
diff -urN a/common/shell.c head/common/shell.c
--- a/common/shell.c	2006-02-21 20:49:02.000000000 +1030
+++ head/common/shell.c	2006-02-25 11:17:36.000000000 +1030
@@ -136,26 +136,29 @@
 }
 
 /*
- * Insert string into rb tree, allocating the string dynamically. If n
- * is NULL, the node structure is also allocated for the caller.
+ * Insert string into rb tree, allocating the node dynamically.
+ * If alloc_str != 0, allocate and copy the string as well.
  * NOTE: These allocations are only on the Temp hunk.
  */
 qboolean
-STree_InsertAlloc(struct stree_root *root, const char *s,
-		  struct stree_node *n)
+STree_InsertAlloc(struct stree_root *root, const char *s, qboolean alloc_str)
 {
     qboolean ret = false;
+    struct stree_node *n;
     char *tmp;
 
-    if (!n)
-	n = STree_AllocNode();
+    n = STree_AllocNode();
     if (n) {
-	tmp = STree_AllocString(strlen(s) + 1);
-	if (tmp) {
-	    strcpy(tmp, s);
-	    n-&gt;string = tmp;
-	    ret = STree_Insert(root, n);
+	if (alloc_str) {
+	    tmp = STree_AllocString(strlen(s) + 1);
+	    if (tmp) {
+		strcpy(tmp, s);
+		n-&gt;string = tmp;
+	    }
+	} else {
+	    n-&gt;string = s;
 	}
+	ret = STree_Insert(root, n);
     }
 
     return ret;
diff -urN a/include/shell.h head/include/shell.h
--- a/include/shell.h	2006-02-21 20:49:02.000000000 +1030
+++ head/include/shell.h	2006-02-25 11:16:37.000000000 +1030
@@ -68,7 +68,7 @@
 void STree_AllocInit(void);
 qboolean STree_Insert(struct stree_root *root, struct stree_node *node);
 qboolean STree_InsertAlloc(struct stree_root *root, const char *s,
-			   struct stree_node *n);
+			   qboolean alloc_str);
 void STree_Remove(struct stree_root *root, struct stree_node *node);
 char *STree_MaxMatch(struct stree_root *root, const char *pfx);
 struct stree_node *STree_Find(struct stree_root *root, const char *s);
</pre></body></html>