[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



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

-- 
Pino Toscano


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