]> jfr.im git - irc/quakenet/newserv.git/commitdiff
Use nsmalloc/nsfree for channel/chanindex.
authorGunnar Beutner <redacted>
Tue, 30 Jul 2013 16:52:22 +0000 (18:52 +0200)
committerGunnar Beutner <redacted>
Tue, 30 Jul 2013 16:52:22 +0000 (18:52 +0200)
chanindex/chanindex.c
channel/channel.c
channel/channel.h
channel/channelalloc.c

index e610fd8e2e960ce8e6b0d7557f65d1314f0d0ed6..fe4f621904960cc59d261176f09c319e0f70a467 100644 (file)
 
 MODULE_VERSION("")
 
-#define ALLOCUNIT      1000
-
 #define channelhash(x)  (crc32i(x)%CHANNELHASHSIZE)
 
 chanindex *chantable[CHANNELHASHSIZE];
 sstring *extnames[MAXCHANNELEXTS];
-chanindex *freechanindices;
 
 unsigned int channelmarker;
 
@@ -26,7 +23,6 @@ void _init() {
   memset(chantable,0,sizeof(chantable));
   memset(extnames,0,sizeof(extnames));
   channelmarker=0;
-  freechanindices=NULL;
 }
 
 void _fini() {
@@ -34,26 +30,11 @@ void _fini() {
 }
 
 chanindex *getchanindex() {
-  int i;
-  chanindex *cip;
-
-  if (freechanindices==NULL) {
-    freechanindices=(chanindex *)nsmalloc(POOL_CHANINDEX, ALLOCUNIT*sizeof(chanindex));
-    for(i=0;i<ALLOCUNIT-1;i++) {
-      freechanindices[i].next=&(freechanindices[i+1]);
-    }
-    freechanindices[ALLOCUNIT-1].next=NULL;
-  }
-
-  cip=freechanindices;
-  freechanindices=cip->next;
-
-  return cip;
+  return nsmalloc(POOL_CHANINDEX, sizeof(chanindex));
 }
 
 void freechanindex(chanindex *cip) {
-  cip->next=freechanindices;
-  freechanindices=cip;
+  nsfree(POOL_CHANINDEX, cip);
 }
 
 chanindex *findchanindex(const char *name) {
index 03ae8f2b43d7c7b0132fd79ee2ccd1ca1d8731da..cf875d4bf2d75dab0860854bb94ebef57e8d1743 100644 (file)
@@ -43,9 +43,6 @@ void channelstats(int hooknum, void *arg);
 void sendchanburst(int hooknum, void *arg);
 
 void _init() {
-  /* Initialise internal structures */
-  initchannelalloc();
-
   /* Set up the nouser marker according to our own numeric */
   nouser=(mylongnum<<18)|CU_NOUSERMASK;
   
index 6c5da84a5e3c3bb94f4aa484f27af4b57d4013a6..0053682b6b30c2358a9206b51f16e69785d8bc0d 100644 (file)
@@ -157,7 +157,6 @@ int addnumerictochanuserhash(chanuserhash *cuh, long numeric);
 unsigned long *getnumerichandlefromchanhash(chanuserhash *cuh, long numeric);
 
 /* functions from channelalloc.c */
-void initchannelalloc();
 channel *newchan();
 void freechan(channel *cp);
 chanuserhash *newchanuserhash(int numbuckets);
index 5add18f6a06766e62212397c7b7000a26dd37127..a71b74576c192c4b710868315e1f26ec718e64d6 100644 (file)
@@ -1,85 +1,36 @@
 /* channelalloc.c */
 
-#include <stdlib.h>
 #include "channel.h"
-#include <assert.h>
 #include "../core/nsmalloc.h"
 
-#define ALLOCUNIT  100
-
-channel *freechans;
-chanuserhash *freehash;
-
-void initchannelalloc() {
-  freechans=NULL;
-  freehash=NULL;
-}
-
-/* channel records don't have next pointers.  
- * Overload the index pointer for chaining free channels */
-
 channel *newchan() {
-  int i;
-  channel *cp;
-  
-  if (freechans==NULL) {
-    freechans=(channel *)nsmalloc(POOL_CHANNEL,ALLOCUNIT*sizeof(channel));
-    for (i=0;i<(ALLOCUNIT-1);i++) {
-      freechans[i].index=(struct chanindex *)&(freechans[i+1]);
-    }
-    freechans[ALLOCUNIT-1].index=NULL;
-  }
-  
-  cp=freechans;
-  freechans=(channel *)cp->index;
-  
-  return cp;
+  return nsmalloc(POOL_CHANNEL, sizeof(channel));
 }
 
 void freechan(channel *cp) {
-  cp->index=(struct chanindex *)freechans;
-  freechans=cp;
+  nsfree(POOL_CHANNEL, cp);
 }
 
-/*
- * Free hash for all!
- *
- * Since these things don't naturally have a "next" pointer
- * we abuse the "content" pointer to build our list of free
- * structures.
- *
- * Hence some somewhat bizarre casts...
- */
-
 chanuserhash *newchanuserhash(int hashsize) {
   int i;
-  chanuserhash *cuhp;
-  
-  if (freehash==NULL) {
-    freehash=(chanuserhash *)nsmalloc(POOL_CHANNEL,ALLOCUNIT*sizeof(chanuserhash));
-    for (i=0;i<(ALLOCUNIT-1);i++) {
-      freehash[i].content=(unsigned long *)&(freehash[i+1]);
-    }    
-    freehash[ALLOCUNIT-1].content=NULL;
-  }
-  
-  cuhp=freehash;
-  freehash=(chanuserhash *)cuhp->content;
-  
+  chanuserhash *cuhp = nsmalloc(POOL_CHANNEL, sizeof(chanuserhash));
+
+  if (!cuhp)
+    return NULL;
+
   /* Don't use nsmalloc() here since we will free this in freechanuserhash() */
   cuhp->content=(unsigned long *)malloc(hashsize*sizeof(unsigned long));
   for (i=0;i<hashsize;i++) {
     cuhp->content[i]=nouser;
   }
-  
+
   cuhp->hashsize=hashsize;
   cuhp->totalusers=0;
-  
+
   return cuhp;
 }
 
 void freechanuserhash(chanuserhash *cuhp) { 
   free(cuhp->content);
-  cuhp->content=(unsigned long *)freehash; 
-  freehash=cuhp;
+  nsfree(POOL_CHANNEL, cuhp);
 }