[Libguestfs] [PATCH 11/14] v2v: In convert function, add a hash of app name -> app structure.

Richard W.M. Jones rjones at redhat.com
Mon Jun 23 11:32:27 UTC 2014


For quicker lookups than searching the linear list.
---
 v2v/convert_linux_enterprise.ml | 15 ++++++++++++++-
 1 file changed, 14 insertions(+), 1 deletion(-)

diff --git a/v2v/convert_linux_enterprise.ml b/v2v/convert_linux_enterprise.ml
index 64eb93d..11627a9 100644
--- a/v2v/convert_linux_enterprise.ml
+++ b/v2v/convert_linux_enterprise.ml
@@ -32,7 +32,9 @@ open Common_utils
 open Utils
 open Types
 
-let rec convert ?(keep_serial_console = true) verbose (g : Guestfs.guestfs)
+module StringMap = Map.Make (String)
+
+let rec convert ?(keep_serial_console = true) verbose (g : G.guestfs)
     ({ i_root = root; i_apps = apps }
         as inspect) source =
   let typ = g#inspect_get_type root
@@ -52,6 +54,17 @@ let rec convert ?(keep_serial_console = true) verbose (g : Guestfs.guestfs)
   and is_suse_family =
     (distro = "sles" || distro = "suse-based" || distro = "opensuse") in
 
+  (* A map of app2_name -> application2, for easier lookups.  Note
+   * that app names are not unique!  (eg. 'kernel' can appear multiple
+   * times)
+   *)
+  let apps_map = List.fold_left (
+    fun map app ->
+      let name = app.G.app2_name in
+      let vs = try StringMap.find name map with Not_found -> [] in
+      StringMap.add name (app :: vs) map
+  ) StringMap.empty apps in
+
   let rec clean_rpmdb () =
     (* Clean RPM database. *)
     assert (package_format = "rpm");
-- 
1.9.0




More information about the Libguestfs mailing list