• R/O
  • SSH
  • HTTPS

tsukurimashou: Commit


Commit MetaInfo

Revision446 (tree)
Time2013-07-25 07:47:43
Authormskala

Log Message

IDSgrep performance tweaks from profiling

Change Summary

Incremental Difference

--- trunk/idsgrep/parse.c (revision 445)
+++ trunk/idsgrep/parse.c (revision 446)
@@ -380,7 +380,20 @@
380380 /* put it in the string, then re-read it as closing bracket */
381381 close_bracket=hchar;
382382 parse_state=(PARSE_STATE)hchar->arity;
383- memcpy(partstr,eptr,clen);
383+ switch (clen) {
384+ case 4:
385+ partstr[3]=eptr[3];
386+ /* FALL THROUGH */
387+ case 3:
388+ partstr[2]=eptr[2];
389+ /* FALL THROUGH */
390+ case 2:
391+ partstr[1]=eptr[1];
392+ /* FALL THROUGH */
393+ case 1:
394+ partstr[0]=eptr[0];
395+ /* FALL THROUGH */
396+ }
384397 partstr_len=clen;
385398 delete_string(hchar);
386399 continue;
@@ -471,8 +484,26 @@
471484 }
472485
473486 /* append the data */
474- memcpy(partstr+partstr_len,eptr,clen);
475- partstr_len+=clen;
487+ switch (clen) {
488+ case 4:
489+ partstr[partstr_len++]=*(eptr++);
490+ /* FALL THROUGH */
491+ case 3:
492+ partstr[partstr_len++]=*(eptr++);
493+ /* FALL THROUGH */
494+ case 2:
495+ partstr[partstr_len++]=*(eptr++);
496+ /* FALL THROUGH */
497+ case 1:
498+ partstr[partstr_len++]=*eptr;
499+ /* FALL THROUGH */
500+ }
501+ /* Note this is the code that the above switch() replaced, but
502+ * the switch() also harmlessly trashes eptr. It works because
503+ * we know clen must be 1, 2, 3, or 4.
504+ * memcpy(partstr+partstr_len,eptr,clen);
505+ * partstr_len+=clen;
506+ */
476507 offs+=clen;
477508 }
478509
--- trunk/idsgrep/hash.c (revision 445)
+++ trunk/idsgrep/hash.c (revision 446)
@@ -27,22 +27,13 @@
2727
2828 /**********************************************************************/
2929
30-#define NUM_BITS (sizeof(size_t)*8)
31-
32-static HASHED_STRING *free_strings[NUM_BITS]={
33-#if SIZEOF_INT>=8
30+static HASHED_STRING *free_strings[64]={
3431 NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,
3532 NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,
36-#endif
37-#if SIZEOF_INT>=6
3833 NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,
3934 NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,
40-#endif
41-#if SIZEOF_INT>=4
4235 NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,
4336 NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,
44-#endif
45- NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,
4637 NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL
4738 };
4839
@@ -49,15 +40,18 @@
4940 NODE *default_match_fn(NODE *);
5041
5142 HASHED_STRING *alloc_string(size_t len) {
52- int i=1;
43+ int i;
5344 HASHED_STRING *rval;
5445 char *save_data;
5546
56- while ((((size_t)1)<<i)<=len) i++;
47+ if (len<=16)
48+ i=4;
49+ else
50+ for (i=5;(((size_t)1)<<i)<len;i++);
5751 if (free_strings[i]==NULL) {
58- rval=(HASHED_STRING *)malloc(sizeof(HASHED_STRING));
52+ rval=(HASHED_STRING *)malloc(sizeof(HASHED_STRING)+(((size_t)1)<<i));
5953 memset(rval,0,sizeof(HASHED_STRING));
60- rval->data=(char *)malloc(((size_t)1)<<i);
54+ rval->data=(char *)(rval+1);
6155 } else {
6256 rval=free_strings[i];
6357 free_strings[i]=rval->next;
@@ -77,9 +71,12 @@
7771 }
7872
7973 void free_string(HASHED_STRING *s) {
80- int i=1;
74+ int i;
8175
82- while ((((size_t)1)<<i)<=s->length) i++;
76+ if (s->length<=16)
77+ i=4;
78+ else
79+ for (i=5;(((size_t)1)<<i)<s->length;i++);
8380 s->next=free_strings[i];
8481 #ifdef HAVE_PCRE
8582 if (s->pcre_compiled) {
@@ -161,7 +158,10 @@
161158 memcpy(tmps->data,s,len);
162159 tmps->data[len]='\0';
163160 tmps->length=len;
164- tmps->refs=1;
161+ if (len==1)
162+ tmps->refs=2;
163+ else
164+ tmps->refs=1;
165165 tmps->next=hash_table[h%hash_table_size];
166166 hash_table[h%hash_table_size]=tmps;
167167 hash_table_occupancy++;
@@ -185,8 +185,6 @@
185185 }
186186 free_string(s);
187187 hash_table_occupancy--;
188-
189- /* FIXME handle shrinking table */
190188 }
191189 }
192190
Show on old repository browser