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

Deduplicate implementation of ;; detection #386

Merged
merged 2 commits into from
Jul 27, 2022
Merged

Deduplicate implementation of ;; detection #386

merged 2 commits into from
Jul 27, 2022

Conversation

Leonidas-from-XIV
Copy link
Collaborator

While pondering a solution for #368 I realized that the code is full of duplicated definitions of ends_by_semi_semi, so I just decided to make it consistent. Mdx.Block might not be the best place to put it, but I gather it is still better than having it copied in 3 places. Interestingly, it was all the same implementation.

4.13 can use String.ends_with but that's a pretty high limit so I decided to use the implementation from Astring to make it a bit more readable, which we depend on already.

@Leonidas-from-XIV Leonidas-from-XIV added the no changelog This PR doesn't require a changelog update label Jul 26, 2022
lib/block.ml Outdated
@@ -219,7 +219,7 @@ let ends_by_semi_semi c =
match List.rev c with
| h :: _ ->
let len = String.length h in
len > 2 && h.[len - 1] = ';' && h.[len - 2] = ';'
len > 2 && Astring.String.is_suffix ~affix:";;" h
Copy link
Collaborator

Choose a reason for hiding this comment

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

Why len > 2 rather than len >= 2 ? (the latter is implicitly checked by is_suffix)

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I assumed that it also checks that there is something in there besides just the ;; but this might have been a typo in the original code. Maybe it really was just a guard for the string subindexing. Removing the check altogether makes the tests all pass so I've amended the code to remove the check.

@Leonidas-from-XIV Leonidas-from-XIV requested a review from Julow July 26, 2022 15:02
This was necessary for the indexing operation but Astring can take care
of it itself.
Copy link
Collaborator

@Julow Julow left a comment

Choose a reason for hiding this comment

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

I think it's fine to remove the len > 2 check.

@Leonidas-from-XIV Leonidas-from-XIV merged commit 0032bc0 into realworldocaml:main Jul 27, 2022
@Leonidas-from-XIV Leonidas-from-XIV deleted the semisemi-dedup branch July 27, 2022 12:48
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
no changelog This PR doesn't require a changelog update
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants