1- use std:: fs;
2- use std:: io:: { self , Write } ;
3- use std:: path:: Path ;
4- use std:: collections:: { HashMap , BTreeMap } ;
1+ use std:: {
2+ collections:: { BTreeMap , HashMap } ,
3+ fs,
4+ io:: { self , Write } ,
5+ path:: Path ,
6+ } ;
7+
58use anyhow:: Context ;
69
710fn main ( ) -> anyhow:: Result < ( ) > {
@@ -10,21 +13,20 @@ fn main() -> anyhow::Result<()> {
1013
1114fn es_preset_env_corejs3_entry ( ) -> anyhow:: Result < ( ) > {
1215 const SEED : u64 = 16416001479773392852 ;
13-
16+
1417 let crate_dir = std:: env:: var ( "CARGO_MANIFEST_DIR" ) ?;
1518 let crate_dir = Path :: new ( & crate_dir) ;
1619
1720 let out_dir = std:: env:: var ( "OUT_DIR" ) . unwrap ( ) ;
1821 let out_dir = Path :: new ( & out_dir) ;
1922 let out_dir = out_dir. join ( "corejs3_entries" ) ;
2023
21-
2224 let entry_path = crate_dir. join ( "data/core-js-compat/entries.json" ) ;
2325 println ! ( "cargo::rerun-if-changed={}" , entry_path. display( ) ) ;
24-
26+
2527 let entry_data = fs:: read_to_string ( entry_path) ?;
26- let entry_data: BTreeMap < & str , Vec < & str > > = serde_json :: from_str ( & entry_data )
27- . context ( "failed to parse entries.json from core js 3" ) ?;
28+ let entry_data: BTreeMap < & str , Vec < & str > > =
29+ serde_json :: from_str ( & entry_data ) . context ( "failed to parse entries.json from core js 3" ) ?;
2830 let ( keys, values) : ( Vec < _ > , Vec < _ > ) = entry_data. into_iter ( ) . unzip ( ) ;
2931
3032 let mut strpool = StrPool :: default ( ) ;
@@ -43,47 +45,46 @@ fn es_preset_env_corejs3_entry() -> anyhow::Result<()> {
4345 let mapout = precomputed_map:: builder:: MapBuilder :: < & str > :: new ( )
4446 . set_seed ( SEED )
4547 . set_hash ( & |seed, & v| {
46- use std:: hash:: { Hash , Hasher } ;
47-
48- let mut hasher = foldhash:: fast:: FoldHasher :: with_seed ( seed, foldhash:: SharedSeed :: global_fixed ( ) ) ;
48+ use std:: hash:: { Hash , Hasher } ;
49+
50+ let mut hasher =
51+ foldhash:: fast:: FoldHasher :: with_seed ( seed, foldhash:: SharedSeed :: global_fixed ( ) ) ;
4952 v. as_bytes ( ) . hash ( & mut hasher) ;
5053 hasher. finish ( )
5154 } )
52- . set_next_seed ( |seed, c| {
53- seed + c
54- } )
55+ . set_next_seed ( |seed, c| seed + c)
5556 . build ( & keys) ?;
5657
57- if let Some ( seed) = mapout. seed ( ) {
58- if seed != SEED {
59- println ! ( "cargo::warning=The seed has changed, please update the seed to {} for faster builds" , seed) ;
60- }
58+ if let Some ( seed) = mapout. seed ( ) . filter ( |& seed| seed != SEED ) {
59+ println ! (
60+ "cargo::warning=The seed has changed, please update the seed to {seed} for faster \
61+ builds"
62+ ) ;
6163 }
6264
6365 // clean file
6466 {
65- fs:: remove_dir_all ( & out_dir)
66- . or_else ( |err| match err. kind ( ) {
67- io:: ErrorKind :: NotFound => Ok ( ( ) ) ,
68- _ => Err ( err)
69- } ) ?;
67+ fs:: remove_dir_all ( & out_dir) . or_else ( |err| match err. kind ( ) {
68+ io:: ErrorKind :: NotFound => Ok ( ( ) ) ,
69+ _ => Err ( err) ,
70+ } ) ?;
7071 fs:: create_dir ( & out_dir) ?;
7172 }
7273
7374 let mut u8seq = precomputed_map:: builder:: U8SeqWriter :: new (
7475 "PrecomputedU8Seq" . into ( ) ,
75- out_dir. join ( "u8.bin" )
76+ out_dir. join ( "u8.bin" ) ,
7677 ) ;
7778 let mut u32seq = precomputed_map:: builder:: U32SeqWriter :: new (
7879 "PrecomputedU32Seq" . into ( ) ,
79- out_dir. join ( "u32.bin" )
80+ out_dir. join ( "u32.bin" ) ,
8081 ) ;
81-
82+
8283 let mut builder = precomputed_map:: builder:: CodeBuilder :: new (
8384 "Corejs3Entries" . into ( ) ,
8485 "SwcFold" . into ( ) ,
8586 & mut u8seq,
86- & mut u32seq
87+ & mut u32seq,
8788 ) ;
8889
8990 let k = builder. create_bytes_position_seq ( "EntryKeys" . into ( ) , mapout. reorder ( & keys) ) ?;
@@ -97,7 +98,8 @@ fn es_preset_env_corejs3_entry() -> anyhow::Result<()> {
9798
9899 fs:: write ( out_dir. join ( "str.bin" ) , strpool. pool . as_bytes ( ) ) ?;
99100
100- writeln ! ( codeout,
101+ writeln ! (
102+ codeout,
101103 "static ENTRY_VALUES_STRING_STORE: &str = include_str!(\" str.bin\" );
102104 static ENTRY_VALUES_LIST: &[Range<u32>] = &["
103105 ) ?;
@@ -119,7 +121,7 @@ impl<'s> StrPool<'s> {
119121 pub fn insert ( & mut self , s : & ' s str ) -> u32 {
120122 * self . map . entry ( s) . or_insert_with ( || {
121123 let offset = self . pool . len ( ) ;
122- self . pool . push_str ( & s) ;
124+ self . pool . push_str ( s) ;
123125 let len: u8 = ( self . pool . len ( ) - offset) . try_into ( ) . unwrap ( ) ;
124126 let offset: u32 = offset. try_into ( ) . unwrap ( ) ;
125127
0 commit comments