[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]

Re: [Libguestfs] [PATCH v2 02/11] resize: add logical_partitions and extended_partition



On Thu, May 28, 2015 at 01:13:28PM +0200, Pino Toscano wrote:
> In data giovedì 28 maggio 2015 12:06:18, Richard W.M. Jones ha scritto:
> > > +  let logical_partitions =
> > > +    List.filter (fun p -> parttype = MBR && p.p_mbr_p_type = LogicalPartition) partitions in
> > > +  (* Filter out logical partitions.  See note above. *)
> > > +  let partitions =
> > > +    (* for GPT, all partitions are regarded as Primary Partition,
> > > +     * e.g. there is no Extended Partition or Logical Partition. *)
> > > +    List.filter (fun p -> parttype <> MBR || p.p_mbr_p_type <> LogicalPartition) partitions in
> > 
> > Although this is code is correct, it is clearer and shorter to write
> > the test using a separate function, so it would become:
> > 
> >   let is_logical_partition p =
> >     parttype = MBR && p.p_mbr_p_type = LogicalPartition
> >   in
> >   let logical_partitions = List.filter is_logical_partition partitions in
> >   let partitions =
> >     List.filter (fun p -> not (is_logical_partition p)) partitions in
> 
> Or, even better:
> 
>   let logical_partitions, partitions =
>     List.partition is_logical_partition partitions in

Indeed, that is better :-)

Rich.

-- 
Richard Jones, Virtualization Group, Red Hat http://people.redhat.com/~rjones
Read my programming and virtualization blog: http://rwmj.wordpress.com
virt-builder quickly builds VMs from scratch
http://libguestfs.org/virt-builder.1.html


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]