]> matita.cs.unibo.it Git - helm.git/commitdiff
removed memory wasting foldright
authorEnrico Tassi <enrico.tassi@inria.fr>
Wed, 22 Jun 2005 11:45:46 +0000 (11:45 +0000)
committerEnrico Tassi <enrico.tassi@inria.fr>
Wed, 22 Jun 2005 11:45:46 +0000 (11:45 +0000)
helm/searchEngine/mooglePp.ml

index 92b55668e5cbe9aa1f5e69194df01c8887d7b37b..8de1426fe77ad267696caacb00ff1b04866f4262 100644 (file)
@@ -23,38 +23,37 @@ let theory_of_result page result =
     Helm_registry.get_int "search_engine.results_per_page"
   in
   let results_no = List.length result in
+  let buffer = Buffer.create (200 * results_no) in
   let result = paginate ~size:results_per_page ~page result in
   if results_no > 0 then
    let mode = "typeonly" in
-   let results =
-    let idx = ref ((page - 1) * results_per_page + List.length result + 1) in
-     List.fold_right
-      (fun uri i ->
-        decr idx ;
-        sprintf
-          "<tr>
-           <td valign=\"top\">%d.</td>
-           <td><span class=\"uri\">%s</span></td>
-           </tr>
-           <tr>
-           <td />
-           <td><ht:OBJECT uri=\"%s\" mode=\"%s\"/></td>
-           </tr>%s"
-          !idx uri uri mode i)
-      result ""
+   let output_results () =
+    let idx = ref ((page - 1) * results_per_page + 1) in
+     List.iter
+      (fun uri ->
+        incr idx;
+        Printf.bprintf buffer 
+           "<tr>
+            <td valign=\"top\">%d.</td>
+            <td><span class=\"uri\">%s</span></td>
+            </tr>
+            <tr>
+            <td />
+            <td><ht:OBJECT uri=\"%s\" mode=\"%s\"/></td>
+            </tr>"
+          !idx uri uri mode) result ;
    in
    let summary =
      sprintf "<b>%d</b> result%s found"
        results_no (if results_no > 1 then "s" else "")
    in
-   let results =
-     sprintf
-       "<table xmlns:ht=\"http://www.cs.unibo.it/helm/namespaces/helm-theory\">
-       %s
-       </table>"
-       results
-   in
-     (summary, results)
+    begin
+     Buffer.add_string buffer
+      "<table xmlns:ht=\"http://www.cs.unibo.it/helm/namespaces/helm-theory\">";
+     output_results ();
+     Buffer.add_string buffer "</table>";
+     (summary, Buffer.contents buffer)
+    end
   else
     ("no results found", "")