Skip to content

fix(utils): use Set for containsAnyOf character check#20

Merged
dhruvanbhalara merged 2 commits into
mainfrom
bugfix/fix-contains-any-of-performance
Jun 9, 2026
Merged

fix(utils): use Set for containsAnyOf character check#20
dhruvanbhalara merged 2 commits into
mainfrom
bugfix/fix-contains-any-of-performance

Conversation

@dhruvanbhalara

Copy link
Copy Markdown
Owner

Use Set-based lookup in the containsAnyOf string extension.

Currently, containsAnyOf uses a linear search on the input character pool string. For long strings and character lists, this can slow down performance. The documentation comment also states that a Set is used for O(1) character lookup, which was not the case in the implementation.

This change converts the input character pool to a Set of runes and searches the target string's runes against it. We also add test cases to test/utils/password_string_extensions_test.dart to verify correct lookup behavior.

Change character search in containsAnyOf to use a Set of runes.
This matches the documentation's claim of O(1) character lookup and improves lookup speed.
Bump library version to 1.0.1 in pubspec.yaml and document the containsAnyOf performance fix in CHANGELOG.md.
@dhruvanbhalara dhruvanbhalara self-assigned this Jun 4, 2026
@dhruvanbhalara dhruvanbhalara marked this pull request as ready for review June 4, 2026 05:31
@dhruvanbhalara dhruvanbhalara merged commit 5a6f17a into main Jun 9, 2026
5 checks passed
@dhruvanbhalara dhruvanbhalara deleted the bugfix/fix-contains-any-of-performance branch June 9, 2026 10:24
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.

1 participant