Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

xapi-idl: Delete String.{explode,implode} functions #5881

Merged
merged 3 commits into from
Aug 2, 2024

Conversation

psafont
Copy link
Member

@psafont psafont commented Jul 24, 2024

These are highly inefficient.

Also changes some functions to be able to have less types and make normal usage
clearer. This comes at the cost of having to destructure the main type when
pattern-matching it.

Moves the device_number tests to its own executable to easily iterate on the
tests.

Drafting as it needs to pass tests regarding urlencoding

@psafont psafont force-pushed the xen_types branch 4 times, most recently from 15eb79b to 7c985e8 Compare July 25, 2024 14:12
@psafont
Copy link
Member Author

psafont commented Jul 25, 2024

I've run a suite to verify that cookie parsing is not disturbed. Most of the code is unit tested (split_f and the device numbers in particular). I think this is ready to go

@psafont psafont marked this pull request as ready for review July 25, 2024 14:13
@@ -81,24 +67,28 @@ module String = struct
in
concat "" (fold_right aux string [])

(** Take a predicate and a string, return a list of strings separated by
runs of characters where the predicate was true (excluding those characters from the result) *)
let split_f p str =
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd rather avoid importing Astring if not needed, the function is well tested with unit tests

)
else
Normal
match List.assoc_opt "class" params with
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These are not related to String.implode, might've been useful to have them in a separate commit.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you update the commit message with a description of what else to expect in this commit? (e.g. the assoc_opt optimization, and I also see some device number handling refactoring)

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've described both changes in the commit. Let me know if it's clarifying enough

@psafont psafont force-pushed the xen_types branch 3 times, most recently from e0dae0f to 6ec4ef6 Compare July 25, 2024 15:08
@psafont psafont force-pushed the xen_types branch 2 times, most recently from 5694ec7 to 50c6f36 Compare July 25, 2024 16:09
if not (String.Sub.is_empty x) then
None
else
Some (pre, post)
in
(* Parse a string "123p456" into x, y where x = 123 and y = 456 *)
Copy link
Contributor

@lindig lindig Jul 29, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why not use sscanf with %dp%d? A lot of this parsing code looks too complicated.

let f s = Scanf.sscanf s "%dp%d" (fun x y -> (x,y));;
utop # f "123p456";;
- : int * int = (123, 456)

Copy link
Contributor

@lindig lindig left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This module has a lot of code that looks too complicated and this is a step in the right direction - especially for functions that are used frequently. I suspect more simplification is possible when it comes to parsing and decomposing strings.

These are highly inefficient.

Also changes some functions to be able to have less types and make normal usage
clearer. This comes at the cost of having to destructure the main type when
pattern-matching it.

Moves the device_number tests to its own executable to easily iterate on the
tests.

Signed-off-by: Pau Ruiz Safont <pau.ruizsafont@cloud.com>
Use the standard ones instead

Signed-off-by: Pau Ruiz Safont <pau.ruizsafont@cloud.com>
The function is implemented using foldleft using a weird form, use a recursive
form instead.

Unfortunately the function was introduced in OCaml 5.1, so it had to be moved
to Listext so it can be reused.

Signed-off-by: Pau Ruiz Safont <pau.ruizsafont@cloud.com>
Copy link
Contributor

@Vincent-lau Vincent-lau left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Original code looks quite complex, but as long as there are good test coverage this should be good

ocaml/xapi-idl/lib_test/device_number_test.ml Show resolved Hide resolved
ocaml/xapi/xapi_dr_task.ml Show resolved Hide resolved
@psafont psafont merged commit 3efc36a into xapi-project:master Aug 2, 2024
15 checks passed
@psafont psafont deleted the xen_types branch August 2, 2024 09:37
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants