improve speed of bag occupied check

This commit is contained in:
Jethro Grassie 2020-10-11 05:08:23 -04:00
parent c3c3318b68
commit 016a4468eb
No known key found for this signature in database
GPG key ID: DE8ED755616565BB
2 changed files with 5 additions and 6 deletions

View file

@ -42,6 +42,7 @@ struct gbag_t
char * b; char * b;
char * n; char * n;
char * ni; char * ni;
char * no;
gbag_recycle rc; gbag_recycle rc;
gbag_moved mv; gbag_moved mv;
}; };
@ -57,6 +58,7 @@ gbag_new(gbag_t **out, size_t count, size_t size,
gb->b = (char*) calloc(gb->max, gb->z); gb->b = (char*) calloc(gb->max, gb->z);
gb->n = gb->b; gb->n = gb->b;
gb->ni = gb->b; gb->ni = gb->b;
gb->no = (char*) calloc(1, size);
gb->rc = recycle; gb->rc = recycle;
gb->mv = moved; gb->mv = moved;
*out = gb; *out = gb;
@ -76,6 +78,7 @@ gbag_free(gbag_t *gb)
} }
} }
free(gb->b); free(gb->b);
free(gb->no);
gb->max = 0; gb->max = 0;
gb->ref = 0; gb->ref = 0;
gb->b = NULL; gb->b = NULL;
@ -89,11 +92,7 @@ gbag_free(gbag_t *gb)
static inline int static inline int
gbag_occupied(gbag_t *gb, char *el) gbag_occupied(gbag_t *gb, char *el)
{ {
char *s = el; return *el || memcmp(el, gb->no, gb->z);
char *e = el + gb->z;
while (s < e)
if (*s++) return 1;
return 0;
} }
void * void *

View file

@ -70,7 +70,7 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#include "uthash.h" #include "uthash.h"
#define MAX_LINE 8192 #define MAX_LINE 8192
#define CLIENTS_INIT 0x4000 #define CLIENTS_INIT 8192
#define RPC_BODY_MAX 8192 #define RPC_BODY_MAX 8192
#define JOB_BODY_MAX 8192 #define JOB_BODY_MAX 8192
#define ERROR_BODY_MAX 512 #define ERROR_BODY_MAX 512