Skip to content

Replace list-then-empty-check patterns with short-circuiting alternatives#224

Merged
sim642 merged 4 commits intodevelopfrom
copilot/audit-list-short-circuiting-opportunities
Mar 24, 2026
Merged

Replace list-then-empty-check patterns with short-circuiting alternatives#224
sim642 merged 4 commits intodevelopfrom
copilot/audit-list-short-circuiting-opportunities

Conversation

Copy link

Copilot AI commented Mar 19, 2026

Several places computed a full filtered list only to check whether it was empty (or use just its first element), wasting work on the remaining elements.

Changes

  • src/check.ml (×2) — label lookup in AddrOfLabel/Goto: replaced List.filter (function Label _ -> …) … :: _ with List.find_opt, which stops at the first Label match.

  • src/frontc/cabs2cil.mlunrollDesignatorForNestedAnonymous: replaced List.filter (fun fld -> fld.fname = designator) + fld :: _ match with List.exists, since the found value is not needed — only whether a matching field exists.

<issue_title>Audit for list short-circuiting opportunities</issue_title>

<issue_description>Similar to #221 look for other instances where a list is first computed to only compare it to the empty list after.</issue_description>

Comments on the Issue (you are @copilot in this section)

Original prompt

This section details on the original issue you should resolve

<issue_title>Audit for list short-circuiting opportunities</issue_title>
<issue_description>Similar to #221 look for other instances where a list is first computed to only compare it to the empty list after.</issue_description>

Comments on the Issue (you are @copilot in this section)


📱 Kick off Copilot coding agent tasks wherever you are with GitHub Mobile, available on iOS and Android.

…ives

Co-authored-by: michael-schwarz <13812333+michael-schwarz@users.noreply.github.com>
Copilot AI changed the title [WIP] Audit for list short-circuiting opportunities Replace list-then-empty-check patterns with short-circuiting alternatives Mar 19, 2026
Copilot AI requested a review from michael-schwarz March 19, 2026 02:14
@michael-schwarz
Copy link
Member

Should be considered in addition to #222.

Co-authored-by: michael-schwarz <13812333+michael-schwarz@users.noreply.github.com>
Copilot AI requested a review from michael-schwarz March 19, 2026 02:18
@michael-schwarz michael-schwarz requested a review from arkocal March 19, 2026 02:19
@michael-schwarz michael-schwarz marked this pull request as ready for review March 19, 2026 02:19
Co-authored-by: michael-schwarz <13812333+michael-schwarz@users.noreply.github.com>
@sim642 sim642 merged commit 2243aad into develop Mar 24, 2026
30 checks passed
@sim642 sim642 deleted the copilot/audit-list-short-circuiting-opportunities branch March 24, 2026 10:26
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.

Audit for list short-circuiting opportunities

3 participants