makedbz -i still running at 125+ hours

Suboptimal Meowbot meowbot at meowing.net
Mon Jun 11 09:01:57 UTC 2001



Speed up makedbz -i by counting history lines up front.

Patch is against current.  I don't think this needs any doc changes.
Not sure that padding the count by 10% is really worthwhile, but it
makes me feel better.
 

--- makedbz.c.orig	Sat Nov  4 21:52:06 2000
+++ makedbz.c	Mon Jun 11 04:51:33 2001
@@ -45,6 +45,43 @@
 #endif
 }
 
+
+/*
+**  Count lines in the history text.  A long-winded way of saying "wc -l"
+*/
+static off_t
+Countlines()
+{
+    QIOSTATE	        *qp;
+    off_t	        count;
+
+    /* Open the text file. */
+    qp = QIOopen(TextFile);
+    if (qp == NULL) {
+	fprintf(stderr, "Can't open \"%s\", %s\n",
+		TextFile, strerror(errno));
+	exit(1);
+    }
+
+    /* Loop through all lines in the text file. */
+    count = 0;
+    for (; QIOread(qp) != NULL;)
+	count++;
+    if (QIOerror(qp)) {
+	fprintf(stderr, "Can't read \"%s\" near line %ld, %s\n",
+		TextFile, count, strerror(errno));
+	exit(1);
+    }
+    if (QIOtoolong(qp)) {
+	fprintf(stderr, "Line %ld of \"%s\" is too long\n", count, TextFile);
+	exit(1);
+    }
+
+    QIOclose(qp);
+    return count;
+}
+
+
 /*
 **  Rebuild the DBZ file from the text file.
 */
@@ -65,6 +102,17 @@
 	exit(1);
     }
 
+    /* If we are ignoring the old database and the user didn't specify
+     * a table size, we determine one ourselves.  The hardcoded
+     * defaults in dbz are often way too small, and this extra walk
+     * through the text can save hours or days of processing. */
+    if (IgnoreOld == TRUE && size == 0) {
+	size = Countlines();
+	size += (size / 10);
+	fprintf(stderr, "no size specified, making room for %ld entries\n",
+		size);
+    }
+
     /* Open the text file. */
     qp = QIOopen(TextFile);
     if (qp == NULL) {
@@ -182,6 +230,8 @@
     if (temp[0])
 	(void)unlink(temp);
 }
+
+
 
 void
 Usage()


More information about the inn-patches mailing list