Replace O(n) List.length comparisons with O(1) List.is_empty#1594
Merged
WardBrian merged 5 commits intostan-dev:masterfrom Feb 23, 2026
Merged
Replace O(n) List.length comparisons with O(1) List.is_empty#1594WardBrian merged 5 commits intostan-dev:masterfrom
WardBrian merged 5 commits intostan-dev:masterfrom
Conversation
List.length traverses the entire list (O(n)) just to compare against zero. List.is_empty is a constant-time check and is already the established idiom elsewhere in the codebase. Changed in: - Warnings.ml: List.length warnings > 0 → not (List.is_empty warnings) - Optimize.ml: List.length l' = 0 → List.is_empty l' (3 occurrences)
Warnings.ml does not open Core, so List refers to the stdlib List module (shadowed by -open Frontend). Use the simpler `warnings <> []` pattern which works in any module context.
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## master #1594 +/- ##
=======================================
Coverage 90.34% 90.34%
=======================================
Files 65 65
Lines 10027 10027
=======================================
Hits 9059 9059
Misses 968 968
🚀 New features to boost your workflow:
|
WardBrian
reviewed
Feb 23, 2026
Member
|
Ah, I see the issue in |
Contributor
Author
oh alright, understood, ill try that |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Submission Checklist
Summary
Fixes #1591
Replace
List.length l = 0andList.length l > 0with the idiomaticList.is_empty/not (List.is_empty ...)in two files:src/frontend/Warnings.ml:List.length warnings > 0→not (List.is_empty warnings)src/analysis_and_optimization/Optimize.ml: 3 occurrences ofList.length ... = 0→List.is_empty ...List.is_emptyis O(1) whileList.lengthtraverses the entire list. The codebase already usesList.is_emptyin 26+ other locations, making these remaining usages inconsistent with the established convention.Release notes
Internal code quality improvement: replace O(n)
List.lengthempty-checks with O(1)List.is_emptyfor consistency and minor performance improvement.Copyright and Licensing
By submitting this pull request, the copyright holder is agreeing to
license the submitted work under the BSD 3-clause license (https://opensource.org/licenses/BSD-3-Clause)
AI Policy
This fix was very straightforwad, hence no AI involvement