-
Notifications
You must be signed in to change notification settings - Fork 503
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* feat: code splitting * chore: update * fix: ci * Use `BitSet` --------- Co-authored-by: Yunfei He <[email protected]>
- Loading branch information
Showing
11 changed files
with
232 additions
and
23 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
use std::fmt::{Debug, Display}; | ||
|
||
#[derive(Clone, PartialEq, Eq, Default, Hash)] | ||
pub struct BitSet { | ||
entries: Vec<u8>, | ||
} | ||
|
||
impl BitSet { | ||
pub fn new(max_bit_count: u32) -> BitSet { | ||
BitSet { | ||
entries: vec![0; ((max_bit_count + 7) / 8) as usize], | ||
} | ||
} | ||
|
||
pub fn has_bit(&self, bit: u32) -> bool { | ||
(self.entries[bit as usize / 8] & (1 << (bit & 7))) != 0 | ||
} | ||
|
||
pub fn set_bit(&mut self, bit: u32) { | ||
self.entries[bit as usize / 8] |= 1 << (bit & 7); | ||
} | ||
} | ||
|
||
impl Display for BitSet { | ||
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { | ||
let bit_string = self | ||
.entries | ||
.iter() | ||
.map(|e| format!("{:08b}", e)) | ||
.collect::<Vec<String>>() | ||
.join("_"); | ||
f.write_str(&bit_string) | ||
} | ||
} | ||
|
||
impl Debug for BitSet { | ||
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { | ||
let bit_string = self | ||
.entries | ||
.iter() | ||
.map(|e| format!("{:08b}", e)) | ||
.collect::<Vec<String>>() | ||
.join("_"); | ||
f.debug_tuple("BitSet").field(&bit_string).finish() | ||
} | ||
} | ||
|
||
#[cfg(test)] | ||
mod tests { | ||
use super::*; | ||
|
||
#[test] | ||
fn basic() { | ||
let mut bs = BitSet::new(1); | ||
assert_eq!(bs.to_string(), "00000000"); | ||
bs.set_bit(0); | ||
bs.set_bit(1); | ||
bs.set_bit(7); | ||
assert_eq!(bs.to_string(), "10000011"); | ||
|
||
let mut bs = BitSet::new(9); | ||
assert_eq!(bs.to_string(), "00000000_00000000"); | ||
bs.set_bit(0); | ||
bs.set_bit(1); | ||
bs.set_bit(7); | ||
assert_eq!(bs.to_string(), "10000011_00000000"); | ||
bs.set_bit(8); | ||
assert_eq!(bs.to_string(), "10000011_00000001"); | ||
bs.set_bit(15); | ||
assert_eq!(bs.to_string(), "10000011_10000001"); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
pub mod bitset; | ||
pub mod bundle; | ||
mod graph; | ||
mod module; | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
21 changes: 21 additions & 0 deletions
21
crates/rolldown/tests/fixtures/code_splitting/artifacts.snap
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
--- | ||
source: crates/rolldown/tests/common/case.rs | ||
expression: content | ||
input_file: crates/rolldown/tests/fixtures/code_splitting | ||
--- | ||
# 2.js | ||
|
||
```js | ||
// share.js | ||
console.log('shared'); | ||
``` | ||
# main1.js | ||
|
||
```js | ||
// main1.js | ||
``` | ||
# main2.js | ||
|
||
```js | ||
// main2.js | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
import './share' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
import './share' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
console.log('shared'); |
14 changes: 14 additions & 0 deletions
14
crates/rolldown/tests/fixtures/code_splitting/test.config.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
{ | ||
"input": { | ||
"input": [ | ||
{ | ||
"name": "main1", | ||
"import": "main1.js" | ||
}, | ||
{ | ||
"name": "main2", | ||
"import": "main2.js" | ||
} | ||
] | ||
} | ||
} |