Skip to content

Conversation

@heathhenley
Copy link
Collaborator

An attempt to address #5

Switched type of tree so that that dir is a Lazy.t and added Lazy.force where needed.

Copy link
Owner

@chshersh chshersh left a comment

Choose a reason for hiding this comment

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

Great job!

I left a few minor comments about using the lazy pattern to slightly simplify some code.

But overall, I like how this refactoring was straightforward 🏆

lib/fs/fs.ml Outdated
Comment on lines 44 to 45
| Dir (name, children) ->
let children = Lazy.force children in
Copy link
Owner

Choose a reason for hiding this comment

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

Let's use the lazy pattern in the pattern matching itself instead of Lazy.force. The behavior will be the same but the code will be slightly terser:

  | Dir (name, lazy children) ->

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

awesome I didn't realize you could do that!

lib/fs/fs.ml Outdated
current = File_cursor (Lazy.force contents);
}
| Dir (_, next) ->
let next = Lazy.force next in
Copy link
Owner

Choose a reason for hiding this comment

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

Same comment about the lazy pattern

Comment on lines +214 to +220
| Dir_selected { children; prev_total; pos } -> (
let children = Lazy.force children in
match children with
(* No children of a directory without children *)
| [||] -> Empty_directory
(* Non-empty array of children *)
| _ -> Directory_contents (children_to_doc ~prev_total ~pos children))
Copy link
Owner

Choose a reason for hiding this comment

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

I think here it's fine to keep Lazy.force because there's no elegant way to pattern-match on a lazy pattern inside record.

@chshersh chshersh added type: refactoring Improving the code quality w/o changing functionality component: performance Performance improvements labels Jan 18, 2025
@chshersh
Copy link
Owner

@heathhenley CI was failing due to some bug in the setup-ocaml action.

I updated the CI, so if you update branches, the CI should start working again.

@chshersh chshersh mentioned this pull request Jan 18, 2025
@heathhenley
Copy link
Collaborator Author

I think I addressed them all - let me know what you think!

Copy link
Owner

@chshersh chshersh left a comment

Choose a reason for hiding this comment

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

Awesome stuff! Let's go!

@chshersh chshersh merged commit e91ad5c into chshersh:main Jan 20, 2025
3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

component: performance Performance improvements type: refactoring Improving the code quality w/o changing functionality

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants