mirror of
https://github.com/swc-project/swc.git
synced 2024-12-01 01:13:56 +03:00
9c8ec0ea56
**Description:** This PR changes the size of `Atom` type to `usize` from 2 * usize`. **Related issue:** - https://github.com/swc-project/swc/issues/4946.
33 lines
1003 B
Rust
33 lines
1003 B
Rust
use std::{env, path::Path};
|
|
|
|
#[cfg(all(feature = "rkyv-impl", feature = "rkyv-bytecheck-impl"))]
|
|
compile_error!("Cannot enable bytechcked, non-bytechecked rkyv both");
|
|
|
|
fn main() {
|
|
let strs = include_str!("words.txt")
|
|
.lines()
|
|
.map(|l| l.trim())
|
|
.collect::<Vec<_>>();
|
|
gen("js_word", "JsWord", &strs);
|
|
}
|
|
|
|
fn gen(mac_name: &str, type_name: &str, atoms: &[&str]) {
|
|
string_cache_codegen::AtomType::new(type_name, &format!("{}!", mac_name))
|
|
.atoms(atoms)
|
|
.with_atom_doc(
|
|
"
|
|
[JsWord] is an interned string.
|
|
|
|
This type should be used instead of [String] for values, because lots of
|
|
values are duplicated. For example, if an identifier is named `myVariable`,
|
|
there will be lots of identifier usages with the value `myVariable`.
|
|
|
|
This type
|
|
- makes equality comparison faster.
|
|
- reduces memory usage.
|
|
",
|
|
)
|
|
.write_to_file(&Path::new(&env::var("OUT_DIR").unwrap()).join(format!("{}.rs", mac_name)))
|
|
.unwrap();
|
|
}
|