Skip to content

Conversation

WooWan
Copy link
Contributor

@WooWan WooWan commented Jun 1, 2024

Summary

The change improves the performance of removing duplicated classNames. In this pull request, I replace the indexOf and splice functions, which have O(n) time complexity, with two separate array filters and a Set().

Comparison

  • Before Change: O(n^2) due to the nested indexOf and splice operations within the filter method.

  • After Change: O(n) due to the use of a Set for constant-time duplicate checks and separate filtering steps.

@thecrypticace thecrypticace changed the title Improve remove duplicate classes Only remove duplicate Tailwind classes Jun 3, 2024
@thecrypticace thecrypticace merged commit 82ea71a into tailwindlabs:main Jun 3, 2024
@thecrypticace
Copy link
Contributor

Thanks! I'd planned to make this improvement this week alongside improving duplicate removal such that it only applies to Tailwind classes but this gave me the push to go ahead and get that done. 🔥

bronisMateusz pushed a commit to bronisMateusz/prettier-plugin-tailwindcss-drupal that referenced this pull request Apr 16, 2025
* improve remove duplicate classes

* replace indexOf by Set

* Simplify code

* Refactor

* Remove duplicates after sorting

* Only remove duplicates of known classes

* Rename vars

* Tweak comment

* Tweak var names

* wip

* Move duplicate removal to sorting routine

* Refactor

* Refactor

* Tweak comment

* Cleanup

* Update changelog

---------

Co-authored-by: Jordan Pittman <[email protected]>
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