瀏覽代碼

Speed up eat_whitespace by a lot.

svn:r8434
Nick Mathewson 17 年之前
父節點
當前提交
b2cc52fa02
共有 2 個文件被更改,包括 15 次插入9 次删除
  1. 1 1
      ChangeLog
  2. 14 8
      src/common/util.c

+ 1 - 1
ChangeLog

@@ -6,7 +6,7 @@ Changes in version 0.1.2.2-alpha - 2006-??-??
       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

+ 14 - 8
src/common/util.c

@@ -413,17 +413,23 @@ eat_whitespace(const char *s)
 {
   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,