httpd-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Dean Gaudet <dgau...@arctic.org>
Subject Re: mod_speling mem usage on large directories
Date Fri, 22 Jan 1999 23:52:52 GMT
Here, try this... it compiles, but I haven't tested it. 

Dean

Index: mod_speling.c
===================================================================
RCS file: /home/cvs/apache-1.3/src/modules/standard/mod_speling.c,v
retrieving revision 1.30
diff -u -r1.30 mod_speling.c
--- mod_speling.c	1999/01/01 19:05:14	1.30
+++ mod_speling.c	1999/01/22 23:52:00
@@ -428,10 +428,13 @@
          * returned.
          */
         else {
-            char *t;
             pool *p;
             table *notes;
+	    pool *sub_pool;
+	    array_header *t;
+	    array_header *v;
 
+
             if (r->main == NULL) {
                 p = r->pool;
                 notes = r->notes;
@@ -441,16 +444,11 @@
                 notes = r->main->notes;
             }
 
+	    sub_pool = ap_make_sub_pool(p);
+	    t = ap_make_array(sub_pool, candidates->nelts * 3, sizeof(char *));
+	    v = ap_make_array(sub_pool, candidates->nelts, sizeof(char *));
+
             /* Generate the response text. */
-            /*
-	     * Since the text is expanded by repeated calls of
-             * t = pstrcat(p, t, ".."), we can avoid a little waste
-             * of memory by adding the header AFTER building the list.
-             * XXX: FIXME: find a way to build a string concatenation
-             *             without repeatedly requesting new memory
-             * XXX: FIXME: Limit the list to a maximum number of entries
-             */
-            t = "";
 
             for (i = 0; i < candidates->nelts; ++i) {
 		char *vuri;
@@ -458,15 +456,15 @@
 
 		reason = sp_reason_str[(int) (variant[i].quality)];
                 /* The format isn't very neat... */
-		vuri = ap_pstrcat(p, url, variant[i].name, r->path_info,
+		vuri = ap_pstrcat(sub_pool, url, variant[i].name, r->path_info,
 				  (r->parsed_uri.query != NULL) ? "?" : "",
 				  (r->parsed_uri.query != NULL)
 				      ? r->parsed_uri.query : "",
 				  NULL);
-		ap_table_mergen(r->subprocess_env, "VARIANTS",
-				ap_pstrcat(p, "\"", vuri, "\";\"",
-					   reason, "\"", NULL));
-                t = ap_pstrcat(p, t, "<li><a href=\"", vuri,
+		*(char **)ap_push_array(v) = ap_pstrcat(sub_pool,
+				  "\"", vuri, "\";\"", reason, "\"", NULL);
+		*(char **)ap_push_array(t) = ap_pstrcat(sub_pool,
+				t, "<li><a href=\"", vuri,
 			       "\">", vuri, "</a> (", reason, ")\n", NULL);
 
                 /*
@@ -479,12 +477,13 @@
                 if (i > 0 && i < candidates->nelts - 1
                     && variant[i].quality != SP_VERYDIFFERENT
                     && variant[i + 1].quality == SP_VERYDIFFERENT) {
-                    t = ap_pstrcat(p, t, 
+		    *(char **)ap_push_array(t) = 
 				   "</ul>\nFurthermore, the following related "
-				   "documents were found:\n<ul>\n", NULL);
+				   "documents were found:\n<ul>\n";
                 }
             }
-            t = ap_pstrcat(p, "The document name you requested (<code>",
+	    *(char **)ap_push_array(t) = ap_pstrcat(sub_pool,
+			  "The document name you requested (<code>",
 			   r->uri,
 			   "</code>) could not be found on this server.\n"
 			   "However, we found documents with names similar "
@@ -493,7 +492,7 @@
 
             /* If we know there was a referring page, add a note: */
             if (ref != NULL) {
-                t = ap_pstrcat(p, t,
+                *(char **)ap_push_array(t) = ap_pstrcat(sub_pool,
 			       "Please consider informing the owner of the "
 			       "<a href=\"", ref, 
 			       "\">referring page</a> "
@@ -501,8 +500,14 @@
 			       NULL);
 	    }
 
+
             /* Pass our table to http_protocol.c (see mod_negotiation): */
-            ap_table_setn(notes, "variant-list", t);
+            ap_table_setn(notes, "variant-list", ap_array_pstrcat(p, t, 0));
+
+	    ap_table_mergen(r->subprocess_env, "VARIANTS",
+			    ap_array_pstrcat(p, v, ','));
+	  
+	    ap_destroy_pool(sub_pool);
 
             ap_log_rerror(APLOG_MARK, APLOG_NOERRNO | APLOG_INFO, r,
 			 ref ? "Spelling fix: %s: %d candidates from %s"


Mime
View raw message