]> jfr.im git - irc/quakenet/newserv.git/commitdiff
Remove custom allocators from nick/patricia.
authorGunnar Beutner <redacted>
Tue, 30 Jul 2013 16:37:22 +0000 (18:37 +0200)
committerGunnar Beutner <redacted>
Tue, 30 Jul 2013 16:37:22 +0000 (18:37 +0200)
nick/nick.c
nick/nick.h
nick/nickalloc.c
patricia/patricia_alloc.c

index edd557cb9fd0aa81fe36b53ed2372260188eabff..e4bb3345f39881aaf904e83ed640578ca2643097 100644 (file)
@@ -66,7 +66,6 @@ void _init() {
     for (anp=authnametable[i];anp;anp=anp->next)
       anp->nicks=NULL;  
 
-  initnickalloc();
   initnickhelpers();
   memset(nicktable,0,sizeof(nicktable));
   memset(servernicks,0,sizeof(servernicks));
index 2212531819b54df54ff111987976ab9cf1be8a8d..8d4daabcc05da64227cee6e43c07c2675ace3de1 100644 (file)
@@ -11,6 +11,7 @@
 #include "../lib/base64.h"
 #include "../lib/irc_ipv6.h"
 #include "../patricia/patricia.h"
+#include "../lib/ccassert.h"
 
 #include "../authext/authext.h"
 
@@ -130,6 +131,8 @@ typedef struct realname {
   struct realname *next;
 } realname;
 
+CCASSERT(sizeof(host) == sizeof(realname));
+
 typedef struct nick {
   char nick[NICKLEN+1];
   long numeric;
@@ -185,13 +188,12 @@ extern char *NULLAUTHNAME;
                                   (((*gethandlebynumeric(x))->numeric==(x&MAXNUMERIC))?(*gethandlebynumeric(x)):NULL)))
 
 /* nickalloc.c functions */
-void initnickalloc();
 realname *newrealname();
 void freerealname(realname *rn);
 nick *newnick();
-void freenick (nick *np);
+void freenick(nick *np);
 host *newhost();
-void freehost (host *hp);
+void freehost(host *hp);
 
 /* nick.c functions */
 void handleserverchange(int hooknum, void *arg);
index 7425f31f1d579e80f4d8d019d3dab3d27ec1151c..64a62b9d878623eb7e75870292554ab7e3cc97c7 100644 (file)
@@ -6,21 +6,9 @@
 #include <assert.h>
 #include <stdlib.h>
 
-#define ALLOCUNIT   100
-
 /* Hosts and realname structures are the same size */
 /* This assumption is checked in initnickalloc(); */
 
-nick *freenicks;
-host *freehosts;
-
-void initnickalloc() {
-  freenicks=NULL;
-  freehosts=NULL;
-  
-  assert(sizeof(host)==sizeof(realname));
-}
-
 realname *newrealname() {
   return (realname *)newhost();
 }
@@ -30,48 +18,18 @@ void freerealname(realname *rn) {
 }
 
 nick *newnick() {
-  nick *np;
-  int i;
-  
-  if (freenicks==NULL) {
-    freenicks=(nick *)nsmalloc(POOL_NICK,ALLOCUNIT*sizeof(nick));
-    for (i=0;i<(ALLOCUNIT-1);i++) {
-      freenicks[i].next=&(freenicks[i+1]);
-    }
-    freenicks[ALLOCUNIT-1].next=NULL;
-  }
-  
-  np=freenicks;
-  freenicks=np->next;
-  
-  return np;
+  return nsmalloc(POOL_NICK, sizeof(nick));
 } 
 
-void freenick (nick *np) {
-  np->next=freenicks;
-  freenicks=np;
+void freenick(nick *np) {
+  nsfree(POOL_NICK, np);
 }
 
 host *newhost() {
-  host *nh;
-  int i;
-  
-  if (freehosts==NULL) {
-    freehosts=(host *)nsmalloc(POOL_NICK,ALLOCUNIT*sizeof(host));
-    for (i=0;i<(ALLOCUNIT-1);i++) {
-      freehosts[i].next=&(freehosts[i+1]);
-    }
-    freehosts[ALLOCUNIT-1].next=NULL;
-  }
-  
-  nh=freehosts;
-  freehosts=nh->next;
-  
-  return nh;
+  return nsmalloc(POOL_NICK, sizeof(host));
 }
 
-void freehost (host *hp) {
-  hp->next=freehosts;
-  freehosts=hp;
+void freehost(host *hp) {
+  nsfree(POOL_NICK, hp);
 }
 
index 33d4ac506bfd5837a1d84ab4a5d3b73f8280f4fb..ed3cd87f0a6f59ddff8c3f9f53de17645f2e3d92 100644 (file)
@@ -4,58 +4,20 @@
 #include <assert.h>
 #include "../core/nsmalloc.h"
 
-#define ALLOCUNIT  100
-
-patricia_node_t *node_freelist;
-union prefixes *prefix_freelist;
-
 prefix_t *newprefix() {
-    union prefixes *prefixes = prefix_freelist;
-    int i;
-
-    if (prefixes==NULL) {
-      prefixes=(union prefixes *)nsmalloc(POOL_PATRICIA,ALLOCUNIT*sizeof(prefix_t));
-
-      for (i=0;i<(ALLOCUNIT-1);i++) {
-        prefixes[i].next=&(prefixes[i+1]);
-      }
-      prefixes[ALLOCUNIT-1].next=NULL;
-    }
-
-    prefix_freelist = prefixes->next;
-    return &(prefixes->prefix);
-
+  return nsmalloc(POOL_PATRICIA, sizeof(prefix_t));
 }
 
-void freeprefix (prefix_t *prefix) {
-  union prefixes *ups =  (union prefixes *)prefix;
-  ups->next = prefix_freelist;
-  prefix_freelist = ups;
+void freeprefix(prefix_t *prefix) {
+  nsfree(POOL_PATRICIA, prefix);
 }
 
-
 patricia_node_t *newnode() {
-  int i;
-  patricia_node_t *node;
-
-  if( node_freelist==NULL ) {
-    node_freelist=(patricia_node_t *)nsmalloc(POOL_PATRICIA,ALLOCUNIT*sizeof(patricia_node_t));
-
-    for (i=0;i<(ALLOCUNIT-1);i++) {
-      node_freelist[i].parent=(patricia_node_t *)&(node_freelist[i+1]);
-    }
-    node_freelist[ALLOCUNIT-1].parent=NULL;
-  }
-
-  node=node_freelist;
-  node_freelist=(patricia_node_t *)node->parent;
-
-  return node;
+  return nsmalloc(POOL_PATRICIA, sizeof(patricia_node_t));
 }
 
-void freenode (patricia_node_t *node) {
- node->parent=(patricia_node_t *)node_freelist;
- node_freelist=node;
+void freenode(patricia_node_t *node) {
+  nsfree(POOL_PATRICIA, node);
 }