Explorar el Código

* Inlined and optimized some of the flag checking functions

svn: 1210
Bryan Drewery hace 22 años
padre
commit
fa19eefabb
Se han modificado 9 ficheros con 43 adiciones y 34 borrados
  1. 1 1
      Makefile.in
  2. 1 0
      doc/UPDATES
  3. 20 12
      src/flags.c
  4. 9 9
      src/flags.h
  5. 4 4
      src/mod/irc.mod/chan.c
  6. 1 1
      src/mod/irc.mod/cmdsirc.c
  7. 2 2
      src/mod/irc.mod/irc.c
  8. 3 3
      src/mod/irc.mod/mode.c
  9. 2 2
      src/mod/irc.mod/msgcmds.c

+ 1 - 1
Makefile.in

@@ -36,7 +36,7 @@ STRIP = @STRIP@
 LIBS = @LIBS@ @ZLIB@ @RESLIB@
 
 DEBCFLAGS = -DDEBUG_ASSERT -DDEBUG_MEM -Dinline= -g3 -ggdb3
-CFLGS = -fno-strict-aliasing -W -Wformat \
+CFLGS = -fno-strict-aliasing -W -Wformat -Winline \
 -Wshadow -Wnested-externs -Wno-format-y2k \
 -Wlarger-than-2048 -Wpointer-arith -Wcast-align \
 -Waggrepate-return -Wlong-long -Wbad-function-cast \

+ 1 - 0
doc/UPDATES

@@ -28,6 +28,7 @@ This is a summary of ChangeLog basically.
 * +take is now enforced much quicker (take() moved up ~300 lines of code)
 * +take now uses MAXMODES-1 deops
 * LAST info for .whois is now properly shared
+* Optimized lots of code to use less CPU
 
 1.1.9
 

+ 20 - 12
src/flags.c

@@ -383,7 +383,8 @@ void get_user_flagrec(struct userrec *u, struct flag_record *fr, const char *chn
  * This function does not check if the user has "op" access, it only checks if the user is
  * restricted by +private for the channel
  */
-int private(struct flag_record fr, struct chanset_t *chan, int type)
+inline int 
+private(struct flag_record fr, struct chanset_t *chan, int type)
 {
   if (!chan || !channel_private(chan) || glob_bot(fr) || glob_owner(fr))
     return 0; /* user is implicitly not restricted by +private, they may however be lacking other flags */
@@ -399,27 +400,29 @@ int private(struct flag_record fr, struct chanset_t *chan, int type)
   return 1; /* user is restricted by +private */
 }
 
-int chk_op(struct flag_record fr, struct chanset_t *chan)
+inline int 
+chk_op(struct flag_record fr, struct chanset_t *chan)
 {
-  if (!chan || (!private(fr, chan, PRIV_OP) && !chk_deop(fr, chan))) {
+  if (!chan || (!private(fr, chan, PRIV_OP) && !chk_deop(fr))) {
     if (chan_op(fr) || (glob_op(fr) && !chan_deop(fr)))
       return 1;
   }
   return 0;
 }
 
-int chk_autoop(struct flag_record fr, struct chanset_t *chan)
+inline int 
+chk_autoop(struct flag_record fr, struct chanset_t *chan)
 {
   if (glob_bot(fr))
     return 0;
-  if (!chan || (!channel_take(chan) && !private(fr, chan, PRIV_OP) && chk_op(fr, chan) && !chk_deop(fr, chan))) {
+  if (!chan || (!channel_take(chan) && !private(fr, chan, PRIV_OP) && chk_op(fr, chan) && !chk_deop(fr))) {
     if (channel_autoop(chan) || chan_autoop(fr) || glob_autoop(fr))
       return 1;
   }
   return 0;
 }
 
-int chk_deop(struct flag_record fr, struct chanset_t *chan)
+inline int chk_deop(struct flag_record fr)
 {
   if (chan_deop(fr) || (glob_deop(fr) && !chan_op(fr)))
     return 1;
@@ -427,16 +430,18 @@ int chk_deop(struct flag_record fr, struct chanset_t *chan)
     return 0;
 }
 
-int chk_voice(struct flag_record fr, struct chanset_t *chan)
+inline int 
+chk_voice(struct flag_record fr, struct chanset_t *chan)
 {
-  if (!chan || (!private(fr, chan, PRIV_VOICE) && !chk_devoice(fr, chan))) {
+  if (!chan || (!private(fr, chan, PRIV_VOICE) && !chk_devoice(fr))) {
     if (chan_voice(fr) || (glob_voice(fr) && !chan_quiet(fr)))
       return 1;
   }
   return 0;
 }
 
-int chk_devoice(struct flag_record fr, struct chanset_t *chan)
+inline int 
+chk_devoice(struct flag_record fr)
 {
   if (chan_quiet(fr) || (glob_quiet(fr) && !chan_voice(fr)))
     return 1;
@@ -444,12 +449,14 @@ int chk_devoice(struct flag_record fr, struct chanset_t *chan)
     return 0;
 }
 
-int chk_noflood(struct flag_record fr, struct chanset_t *chan)
+inline int 
+chk_noflood(struct flag_record fr)
 {
   return (chan_noflood(fr) || glob_noflood(fr));
 }
 
-int isupdatehub()
+inline int 
+isupdatehub()
 {
 #ifdef HUB
   if (conf.bot->u && (conf.bot->u->flags & USER_UPDATEHUB))
@@ -459,7 +466,8 @@ int isupdatehub()
     return 0;
 }
 
-int ischanhub()
+inline int 
+ischanhub()
 {
   if (conf.bot->u && (conf.bot->u->flags & USER_CHANHUB))
     return 1;

+ 9 - 9
src/flags.h

@@ -135,15 +135,15 @@ flag_t sanity_check(flag_t, int);
 flag_t chan_sanity_check(flag_t, flag_t);
 char geticon(int);
 
-int private(struct flag_record, struct chanset_t *, int);
-int chk_op(struct flag_record, struct chanset_t *);
-int chk_autoop(struct flag_record, struct chanset_t *);
-int chk_deop(struct flag_record, struct chanset_t *);
-int chk_voice(struct flag_record, struct chanset_t *);
-int chk_devoice(struct flag_record, struct chanset_t *);
-int chk_noflood(struct flag_record, struct chanset_t *);
-int ischanhub();
-int isupdatehub();
+inline int private(struct flag_record, struct chanset_t *, int);
+inline int chk_op(struct flag_record, struct chanset_t *);
+inline int chk_autoop(struct flag_record, struct chanset_t *);
+inline int chk_deop(struct flag_record);
+inline int chk_voice(struct flag_record, struct chanset_t *);
+inline int chk_devoice(struct flag_record);
+inline int chk_noflood(struct flag_record);
+inline int ischanhub();
+inline int isupdatehub();
 int dovoice(struct chanset_t *);
 int dolimit(struct chanset_t *);
 int whois_access(struct userrec *, struct userrec *);

+ 4 - 4
src/mod/irc.mod/chan.c

@@ -352,7 +352,7 @@ static int detect_chan_flood(char *floodnick, char *floodhost, char *from,
       ((which == FLOOD_KICK) &&
        (glob_master(fr) || chan_master(fr))) ||
       ((which != FLOOD_DEOP) && (which != FLOOD_KICK) && 
-       (glob_noflood(fr) || chan_noflood(fr))))
+       (chk_noflood(fr))))
     return 0;
 
   /* Determine how many are necessary to make a flood. */
@@ -917,7 +917,7 @@ static void check_this_member(struct chanset_t *chan, char *nick, struct flag_re
     /* +d or bitch and not an op
      * we dont check private because +private does not imply bitch. */
     if (chan_hasop(m) && 
-        (chk_deop(*fr, chan) ||
+        (chk_deop(*fr) ||
          (!loading && userlist && channel_bitch(chan) && !chk_op(*fr, chan)) ) ) {
       /* if (target_priority(chan, m, 1)) */
         add_mode(chan, '-', 'o', m->nick);
@@ -927,7 +927,7 @@ static void check_this_member(struct chanset_t *chan, char *nick, struct flag_re
     if (dovoice(chan)) {
       if (chan_hasvoice(m) && !chan_hasop(m)) {
         /* devoice +q users .. */
-        if (chk_devoice(*fr, chan))
+        if (chk_devoice(*fr))
           add_mode(chan, '-', 'v', m->nick);
       } else if (!chan_hasvoice(m) && !chan_hasop(m)) {
         /* voice +v users */
@@ -1479,7 +1479,7 @@ static int got352or4(struct chanset_t *chan, char *user, char *host, char *serve
   get_user_flagrec(m->user, &fr, chan->dname);
   /* are they a chanop, and me too */
       /* are they a channel or global de-op */
-  if (chan_hasop(m) && me_op(chan) && chk_deop(fr, chan) && !match_my_nick(nick)) 
+  if (chan_hasop(m) && me_op(chan) && chk_deop(fr) && !match_my_nick(nick)) 
       /* && target_priority(chan, m, 1) */
     add_mode(chan, '-', 'o', nick);
 

+ 1 - 1
src/mod/irc.mod/cmdsirc.c

@@ -489,7 +489,7 @@ static void cmd_op(struct userrec *u, int idx, char *par)
   egg_snprintf(s, sizeof s, "%s!%s", m->nick, m->userhost);
   u = get_user_by_host(s);
   get_user_flagrec(u, &victim, chan->dname);
-  if (chk_deop(victim, chan)) {
+  if (chk_deop(victim)) {
     dprintf(idx, "%s is currently being auto-deopped  on %s.\n", m->nick, chan->dname);
     if (all) goto next;
     return;

+ 2 - 2
src/mod/irc.mod/irc.c

@@ -1189,12 +1189,12 @@ check_expired_chanstuff(struct chanset_t *chan)
           struct flag_record fr2 = { FR_GLOBAL | FR_CHAN, 0, 0, 0 };
           get_user_flagrec(m->user, &fr2, chan->dname);
           if (!private(fr2, chan, PRIV_VOICE) &&
-              ((channel_voice(chan) && !chk_devoice(fr2, chan)) ||
+              ((channel_voice(chan) && !chk_devoice(fr2)) ||
                (!channel_voice(chan) && chk_voice(fr2, chan))) &&
               !glob_bot(fr2) && !chan_hasop(m) && !chan_hasvoice(m) && !(m->flags & EVOICE)) {
             putlog(LOG_DEBUG, "@", "VOICING %s in %s as '%s'", m->nick, chan->dname, m->user->handle);
             add_mode(chan, '+', 'v', m->nick);
-          } else if (!glob_bot(fr2) && (chk_devoice(fr2, chan) || (m->flags & EVOICE))) {
+          } else if (!glob_bot(fr2) && (chk_devoice(fr2) || (m->flags & EVOICE))) {
             if (!chan_hasop(m) && chan_hasvoice(m))
               add_mode(chan, '-', 'v', m->nick);
           }

+ 3 - 3
src/mod/irc.mod/mode.c

@@ -490,7 +490,7 @@ got_op(struct chanset_t *chan, char *nick, char *from,
       nick[0]) {
     /* Channis is +bitch, and the opper isn't a global master or a bot */
     /* deop if they are +d or it is +bitch */
-    if (chk_deop(victim, chan) || (!loading && userlist && channel_bitch(chan) && !chk_op(victim, chan))) {     /* chk_op covers +private */
+    if (chk_deop(victim) || (!loading && userlist && channel_bitch(chan) && !chk_op(victim, chan))) {     /* chk_op covers +private */
 /*      char outbuf[101] = ""; */
 
       /* if (target_priority(chan, m, 1)) */
@@ -506,7 +506,7 @@ got_op(struct chanset_t *chan, char *nick, char *from,
   } else if (reversing && !match_my_nick(who))
     add_mode(chan, '-', 'o', who);
   if (!nick[0] && me_op(chan) && !match_my_nick(who)) {
-    if (chk_deop(victim, chan)) {
+    if (chk_deop(victim)) {
       m->flags |= FAKEOP;
       add_mode(chan, '-', 'o', who);
     } else if (snm > 0 && snm < 7 && !((0 || 0 ||
@@ -1341,7 +1341,7 @@ gotmode(char *from, char *msg)
                 m->flags &= ~SENTVOICE;
                 m->flags |= CHANVOICE;
                 if (channel_active(chan) && dovoice(chan)) {
-                  if (dv || chk_devoice(victim, chan)) {
+                  if (dv || chk_devoice(victim)) {
                     add_mode(chan, '-', 'v', op);
                   } else if (reversing) {
                     add_mode(chan, '-', 'v', op);

+ 2 - 2
src/mod/irc.mod/msgcmds.c

@@ -589,7 +589,7 @@ static int msgc_voice(char *nick, char *host, struct userrec *u, char *chname, c
       chan = findchan_by_dname(par);
     if (chan && channel_active(chan)) {
       get_user_flagrec(u, &fr, chan->dname);
-      if (!chk_devoice(fr, chan)) {		/* dont voice +q */
+      if (!chk_devoice(fr)) {		/* dont voice +q */
         add_mode(chan, '+', 'v', nick);
       }
       return BIND_RET_BREAK;
@@ -597,7 +597,7 @@ static int msgc_voice(char *nick, char *host, struct userrec *u, char *chname, c
   } else {
     for (chan = chanset; chan; chan = chan->next) {
       get_user_flagrec(u, &fr, chan->dname);
-      if (!chk_devoice(fr, chan)) {		/* dont voice +q */
+      if (!chk_devoice(fr)) {		/* dont voice +q */
         add_mode(chan, '+', 'v', nick);
       }
     }