Skip to content

Commit

Permalink
Always sort candidates (#10382)
Browse files Browse the repository at this point in the history
* Always sort candidates

* Sort candidates in Rust in Oxide engine

Co-authored-by: Adam Wathan <[email protected]>
  • Loading branch information
adamwathan and adamwathan authored Jan 21, 2023
1 parent e17855b commit ed8ff92
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 14 deletions.
6 changes: 4 additions & 2 deletions oxide/crates/core/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ fn parse_all_blobs(blobs: Vec<Vec<u8>>) -> Vec<String> {
let input: Vec<_> = blobs.iter().map(|blob| &blob[..]).collect();
let input = &input[..];

input
let mut result: Vec<String> = input
.par_iter()
.map(|input| Extractor::unique(input, Default::default()))
.reduce(Default::default, |mut a, b| {
Expand All @@ -68,5 +68,7 @@ fn parse_all_blobs(blobs: Vec<Vec<u8>>) -> Vec<String> {
// to a string.
unsafe { String::from_utf8_unchecked(s.to_vec()) }
})
.collect()
.collect();
result.sort();
result
}
21 changes: 9 additions & 12 deletions src/lib/expandTailwindAtRules.js
Original file line number Diff line number Diff line change
Expand Up @@ -163,19 +163,16 @@ export default function expandTailwindAtRules(context) {
let classCacheCount = context.classCache.size

env.DEBUG && console.time('Generate rules')
// TODO: Sorting is _probably_ slow, but right now it can guarantee the same order. Eventually
// we will be able to get rid of this.
env.DEBUG && console.time('Sorting candidates')
let sortedCandidates =
typeof process !== 'undefined' && process.env.JEST_WORKER_ID
? new Set(
[...candidates].sort((a, z) => {
if (a === z) return 0
if (a < z) return -1
return 1
})
)
: candidates
let sortedCandidates = env.OXIDE
? candidates
: new Set(
[...candidates].sort((a, z) => {
if (a === z) return 0
if (a < z) return -1
return 1
})
)
env.DEBUG && console.timeEnd('Sorting candidates')
generateRules(sortedCandidates, context)
env.DEBUG && console.timeEnd('Generate rules')
Expand Down

0 comments on commit ed8ff92

Please sign in to comment.