From dc4b58afdf53b96fb9163d396dab24b8c8ebcaa0 Mon Sep 17 00:00:00 2001 From: Enrico Tassi Date: Wed, 22 Jun 2005 11:45:46 +0000 Subject: [PATCH] removed memory wasting foldright --- helm/searchEngine/mooglePp.ml | 47 +++++++++++++++++------------------ 1 file changed, 23 insertions(+), 24 deletions(-) diff --git a/helm/searchEngine/mooglePp.ml b/helm/searchEngine/mooglePp.ml index 92b55668e..8de1426fe 100644 --- a/helm/searchEngine/mooglePp.ml +++ b/helm/searchEngine/mooglePp.ml @@ -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 - " - %d. - %s - - - - - %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 + " + %d. + %s + + + + + " + !idx uri uri mode) result ; in let summary = sprintf "%d result%s found" results_no (if results_no > 1 then "s" else "") in - let results = - sprintf - " - %s -
" - results - in - (summary, results) + begin + Buffer.add_string buffer + ""; + output_results (); + Buffer.add_string buffer "
"; + (summary, Buffer.contents buffer) + end else ("no results found", "") -- 2.39.2