* sysdep.c: optimized MyContext() a bit, and inlined it. A little profiling
authorArt Cancro <ajc@citadel.org>
Tue, 1 Apr 2003 05:01:08 +0000 (05:01 +0000)
committerArt Cancro <ajc@citadel.org>
Tue, 1 Apr 2003 05:01:08 +0000 (05:01 +0000)
  revealed that this function was getting used super heavily.
* tools.c: removed the older, slower string tokenizer functions that
  weren't getting used anymore.

citadel/ChangeLog
citadel/server.h
citadel/sysdep.c
citadel/sysdep_decls.h
citadel/tools.c

index 97f1cc888c7cf62c4d990aa94fda7a7330143433..1c9357ed34a5512b4712c63499e56e13ee614541 100644 (file)
@@ -1,4 +1,10 @@
  $Log$
+ Revision 605.31  2003/04/01 05:01:08  ajc
+ * sysdep.c: optimized MyContext() a bit, and inlined it.  A little profiling
+   revealed that this function was getting used super heavily.
+ * tools.c: removed the older, slower string tokenizer functions that
+   weren't getting used anymore.
+
  Revision 605.30  2003/03/31 04:55:58  ajc
  * Repaired the formatting of text/plain messages with blank lines.
 
@@ -4606,3 +4612,4 @@ Sat Jul 11 00:20:48 EDT 1998 Nathan Bryant <bryant@cs.usm.maine.edu>
 
 Fri Jul 10 1998 Art Cancro <ajc@uncensored.citadel.org>
        * Initial CVS import
+
index 1866d3c3d5e1925437c7ec6f700fa8f8b72832c0..d99be8ddf38c0ec39ede4b280be0e37eb092baab 100644 (file)
@@ -152,7 +152,7 @@ enum {
 #define CS_POSTING     4       /* Posting */
 
 struct CitContext *MyContext(void);
-#define CC ((struct CitContext *)MyContext())
+#define CC MyContext()
 
 extern struct CitContext *ContextList;
 extern int ScheduledShutdown;
index 243c299979dbac4ef69a089f1c23a82cb352b6a1..bc3db99164f10991ec1dd8eb2054fe7f095bbc0d 100644 (file)
@@ -408,12 +408,14 @@ int ig_uds_server(char *sockpath, int queue_len)
  * Return a pointer to the CitContext structure bound to the thread which
  * called this function.  If there's no such binding (for example, if it's
  * called by the housekeeper thread) then a generic 'master' CC is returned.
+ *
+ * It's inlined because it's used *VERY* frequently.
  */
-struct CitContext *MyContext(void) {
-       struct CitContext *retCC;
-       retCC = (struct CitContext *) pthread_getspecific(MyConKey);
-       if (retCC == NULL) retCC = &masterCC;
-       return(retCC);
+inline struct CitContext *MyContext(void) {
+       return ((pthread_getspecific(MyConKey) == NULL)
+               ? &masterCC
+               : (struct CitContext *) pthread_getspecific(MyConKey)
+       );
 }
 
 
index 023ee935ad07522e59402e26a39e1bc7e7d126f5..406e8f68924cbcfb7747663bd62988cacdf6340a 100644 (file)
@@ -17,7 +17,7 @@ void begin_critical_section (int which_one);
 void end_critical_section (int which_one);
 int ig_tcp_server (int port_number, int queue_len);
 int ig_uds_server(char *sockpath, int queue_len);
-struct CitContext *MyContext (void);
+inline struct CitContext *MyContext (void);
 struct CitContext *CreateNewContext (void);
 void InitMyContext (struct CitContext *con);
 void client_write (char *buf, int nbytes);
index c4a3ca4307c4015b16f442f6d54622e3594cb521..a241d2907da771f0a2cd455dd57c4390385838b0 100644 (file)
@@ -86,7 +86,7 @@ int num_tokens(const char *source, char tok) {
 }
 
 
-/* extract_token_fast() - a smarter string tokenizer */
+/* extract_token() - a smarter string tokenizer */
 void extract_token(char *dest, const char *source, unsigned long parmnum, char separator)
 {
        char *d;                /* dest */
@@ -117,37 +117,7 @@ void extract_token(char *dest, const char *source, unsigned long parmnum, char s
 }
 
 
-/*
- * extract_token()  -  a smarter string tokenizer
- */
-void extract_token_old(char *dest, const char *source, unsigned long parmnum, char separator) 
-{
-       int i;
-       int len;
-       int curr_parm;
-
-       strcpy(dest,"");
-       len = 0;
-       curr_parm = 0;
-
-       if (strlen(source)==0) {
-               return;
-       }
-
-       for (i=0; i<strlen(source); ++i) {
-               if (source[i]==separator) {
-                       ++curr_parm;
-               }
-               else if (curr_parm == parmnum) {
-                       dest[len+1] = 0;
-                       dest[len++] = source[i];
-               }
-       }
-}
-
-
-
-/* remove_token_fast() - a tokenizer that kills, maims, and destroys fast */
+/* remove_token() - a tokenizer that kills, maims, and destroys fast */
 void remove_token(char *source, unsigned long parmnum, char separator)
 {
        char *d, *s;            /* dest, source */
@@ -190,46 +160,6 @@ void remove_token(char *source, unsigned long parmnum, char separator)
 }
 
 
-/*
- * remove_token()  -  a tokenizer that kills, maims, and destroys
- */
-void remove_token_old(char *source, int parmnum, char separator)
-{
-       int i;
-       int len;
-       int curr_parm;
-       int start, end;
-
-       len = 0;
-       curr_parm = 0;
-       start = (-1);
-       end = (-1);
-
-       if (strlen(source)==0) {
-               return;
-       }
-
-       for (i=0; i<strlen(source); ++i) {
-               if ( (start < 0) && (curr_parm == parmnum) ) {
-                       start = i;
-               }
-
-               if ( (end < 0) && (curr_parm == (parmnum+1)) ) {
-                       end = i;
-               }
-
-               if (source[i]==separator) {
-                       ++curr_parm;
-               }
-       }
-
-       if (end < 0) end = strlen(source);
-       strcpy(&source[start], &source[end]);
-}
-
-
-
-
 /*
  * extract_int()  -  extract an int parm w/o supplying a buffer
  */