[Libguestfs] [PATCH 2/2] dib: use remove_duplicates instead of own code

Richard W.M. Jones rjones at redhat.com
Fri Sep 23 18:17:05 UTC 2016


On Fri, Sep 23, 2016 at 06:05:25PM +0200, Pino Toscano wrote:
> Use a common function to remove duplicates in an unsorted list.
> 
> Just refactoring, with no behaviour change.

Except it's no longer O(n^2) :-)

ACK series.

Rich.

> ---
>  dib/cmdline.ml | 2 +-
>  dib/utils.ml   | 4 ----
>  2 files changed, 1 insertion(+), 5 deletions(-)
> 
> diff --git a/dib/cmdline.ml b/dib/cmdline.ml
> index 1fd6c71..144e5a7 100644
> --- a/dib/cmdline.ml
> +++ b/dib/cmdline.ml
> @@ -107,7 +107,7 @@ read the man page virt-dib(1).
>  
>    let formats = ref ["qcow2"] in
>    let set_format arg =
> -    let fmts = remove_dups (String.nsplit "," arg) in
> +    let fmts = remove_duplicates (String.nsplit "," arg) in
>      List.iter (
>        function
>        | "qcow2" | "tar" | "raw" | "vhd" | "docker" -> ()
> diff --git a/dib/utils.ml b/dib/utils.ml
> index a2046cb..3df5171 100644
> --- a/dib/utils.ml
> +++ b/dib/utils.ml
> @@ -91,10 +91,6 @@ let digit_prefix_compare a b =
>  let do_mkdir dir =
>    mkdir_p dir 0o755
>  
> -let rec remove_dups = function
> -  | [] -> []
> -  | x :: xs -> x :: (remove_dups (List.filter ((<>) x) xs))
> -
>  let require_tool tool =
>    try ignore (which tool)
>    with Executable_not_found tool ->
> -- 
> 2.7.4
> 
> _______________________________________________
> Libguestfs mailing list
> Libguestfs at redhat.com
> https://www.redhat.com/mailman/listinfo/libguestfs

-- 
Richard Jones, Virtualization Group, Red Hat http://people.redhat.com/~rjones
Read my programming and virtualization blog: http://rwmj.wordpress.com
libguestfs lets you edit virtual machines.  Supports shell scripting,
bindings from many languages.  http://libguestfs.org




More information about the Libguestfs mailing list