Skip to content

Commit

Permalink
Change List.length l > 0 to l <> [], avoiding an unnecessary iteration
Browse files Browse the repository at this point in the history
Signed-off-by: Andrii Sultanov <[email protected]>
  • Loading branch information
last-genius committed Dec 12, 2024
1 parent 6bc999f commit 623e263
Show file tree
Hide file tree
Showing 4 changed files with 6 additions and 6 deletions.
2 changes: 1 addition & 1 deletion oxenstored/connection.ml
Original file line number Diff line number Diff line change
Expand Up @@ -344,7 +344,7 @@ let del_watch con path token =
let ws = Hashtbl.find con.watches apath in
let w = List.find (fun w -> w.token = token) ws in
let filtered = Utils.list_remove w ws in
if List.length filtered > 0 then
if filtered <> [] then
Hashtbl.replace con.watches apath filtered
else
Hashtbl.remove con.watches apath ;
Expand Down
2 changes: 1 addition & 1 deletion oxenstored/process.ml
Original file line number Diff line number Diff line change
Expand Up @@ -336,7 +336,7 @@ let do_debug con t _domains cons data =
let do_directory con t _domains _cons data =
let path = split_one_path data con in
let entries = Transaction.ls t (Connection.get_perm con) path in
if List.length entries > 0 then
if entries <> [] then
Utils.join_by_null entries ^ "\000"
else
""
Expand Down
4 changes: 2 additions & 2 deletions oxenstored/transaction.ml
Original file line number Diff line number Diff line change
Expand Up @@ -269,7 +269,7 @@ let ls_partial t perm path directory_cache max_gen_count =
| None ->
let node, entries = Store.ls t.store perm path in
let r =
if List.length entries > 0 then
if entries <> [] then
Utils.join_by_null entries ^ "\000"
else
""
Expand All @@ -293,7 +293,7 @@ let getperms t perm path =
set_read_lowpath t path ; r

let commit ~con t =
let has_write_ops = List.length t.paths > 0 in
let has_write_ops = t.paths <> [] in
let has_coalesced = ref false in
let has_commited =
match t.ty with
Expand Down
4 changes: 2 additions & 2 deletions oxenstored/xenstored.ml
Original file line number Diff line number Diff line change
Expand Up @@ -687,10 +687,10 @@ let () =
with Unix.Unix_error (Unix.EINTR, _, _) -> ([], [], [])
in
let sfds, cfds = List.partition (fun fd -> List.mem fd spec_fds) rset in
if List.length sfds > 0 then
if sfds <> [] then
process_special_fds sfds ;

if List.length cfds > 0 || List.length wset > 0 then
if cfds <> [] || wset <> [] then
process_connection_fds store cons domains cfds wset ;
( if timeout <> 0. then
let now = Unix.gettimeofday () in
Expand Down

0 comments on commit 623e263

Please sign in to comment.