[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]

[or-cvs] r8434: Speed up eat_whitespace by a lot. (in tor/trunk: . src/common)



Author: nickm
Date: 2006-09-19 19:55:35 -0400 (Tue, 19 Sep 2006)
New Revision: 8434

Modified:
   tor/trunk/ChangeLog
   tor/trunk/src/common/util.c
Log:
Speed up eat_whitespace by a lot.

Modified: tor/trunk/ChangeLog
===================================================================
--- tor/trunk/ChangeLog	2006-09-19 23:48:14 UTC (rev 8433)
+++ tor/trunk/ChangeLog	2006-09-19 23:55:35 UTC (rev 8434)
@@ -6,7 +6,7 @@
       one.
 
   o Minor Bugfixes
-    - Small performance improvements on parsing descriptors.
+    - Small performance improvements on parsing descriptors (x2).
     - Major performance descriptor on inserting descriptors; change
       algorithm from O(n^2) to O(n).
     - Make the common memory allocation path faster on machines where

Modified: tor/trunk/src/common/util.c
===================================================================
--- tor/trunk/src/common/util.c	2006-09-19 23:48:14 UTC (rev 8433)
+++ tor/trunk/src/common/util.c	2006-09-19 23:55:35 UTC (rev 8434)
@@ -413,17 +413,23 @@
 {
   tor_assert(s);
 
-  while (TOR_ISSPACE(*s) || *s == '#') {
-    while (TOR_ISSPACE(*s))
-      s++;
-    if (*s == '#') { /* read to a \n or \0 */
+  while (1) {
+    switch (*s) {
+    case '\0':
+    default:
+      return s;
+    case ' ':
+    case '\t':
+    case '\n':
+    case '\r':
+      ++s;
+      break;
+    case '#':
+      ++s;
       while (*s && *s != '\n')
-        s++;
-      if (!*s)
-        return s;
+        ++s;
     }
   }
-  return s;
 }
 
 /** Return a pointer to the first char of s that is not a space or a tab,