Skip to content

Simplify Starlark prefix and suffix checks with tuples - #832

Open
dzbarsky wants to merge 4 commits into
bazelbuild:mainfrom
dzbarsky:codex/simplify-extension-checks
Open

Simplify Starlark prefix and suffix checks with tuples#832
dzbarsky wants to merge 4 commits into
bazelbuild:mainfrom
dzbarsky:codex/simplify-extension-checks

Conversation

@dzbarsky

@dzbarsky dzbarsky commented Aug 2, 2026

Copy link
Copy Markdown
Contributor

Starlark strings startswith and endswith, like their Python counterparts, support batch checking against a tuple of possible endings. Use that capability instead of Starlark loops, since any reasonable implementation should be able to optimize this better.

@dzbarsky
dzbarsky marked this pull request as ready for review August 3, 2026 00:00
Comment thread cc/common/cc_helper.bzl
has_legacy_link_shared_name = (_is_link_shared(ctx) and
(_matches([".so", ".dylib", ".dll", ".pyd"], target_name) or
cc_helper.is_valid_shared_library_name(target_name)))
has_legacy_link_shared_name = _is_link_shared(ctx) and cc_helper.is_valid_shared_library_name(target_name)

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

should this be an "or" instead? the _matches is redundant with is_valid_shared_library_name, but is_valid_shared_library_name should be sufficient even when not _is_link_shared

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Using or would change behavior for targets with shared-library filenames but linkshared = False. Not sure if we care but I erred toward making this a pure perf improvement to be safe

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

you're right; I mis-read the parentheses.

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.

2 participants