mirror of
https://github.com/denoland/deno.git
synced 2025-08-04 02:48:24 +00:00
refactor: make version and user_agent &'static str (#18400)
These caused a bunch of unnecessary allocations on each startup.
This commit is contained in:
parent
edab8f2fd4
commit
275dee60e7
14 changed files with 91 additions and 79 deletions
23
cli/cache/parsed_source.rs
vendored
23
cli/cache/parsed_source.rs
vendored
|
@ -54,7 +54,7 @@ impl deno_graph::ParsedSourceStore for ParsedSourceCacheSources {
|
|||
#[derive(Clone)]
|
||||
pub struct ParsedSourceCache {
|
||||
db_cache_path: Option<PathBuf>,
|
||||
cli_version: String,
|
||||
cli_version: &'static str,
|
||||
sources: ParsedSourceCacheSources,
|
||||
}
|
||||
|
||||
|
@ -70,7 +70,7 @@ impl ParsedSourceCache {
|
|||
pub fn reset_for_file_watcher(&self) -> Self {
|
||||
Self {
|
||||
db_cache_path: self.db_cache_path.clone(),
|
||||
cli_version: self.cli_version.clone(),
|
||||
cli_version: self.cli_version,
|
||||
sources: Default::default(),
|
||||
}
|
||||
}
|
||||
|
@ -116,7 +116,7 @@ impl ParsedSourceCache {
|
|||
pub fn as_analyzer(&self) -> Box<dyn deno_graph::ModuleAnalyzer> {
|
||||
match ParsedSourceCacheModuleAnalyzer::new(
|
||||
self.db_cache_path.as_deref(),
|
||||
self.cli_version.clone(),
|
||||
self.cli_version,
|
||||
self.sources.clone(),
|
||||
) {
|
||||
Ok(analyzer) => Box::new(analyzer),
|
||||
|
@ -146,7 +146,7 @@ struct ParsedSourceCacheModuleAnalyzer {
|
|||
impl ParsedSourceCacheModuleAnalyzer {
|
||||
pub fn new(
|
||||
db_file_path: Option<&Path>,
|
||||
cli_version: String,
|
||||
cli_version: &'static str,
|
||||
sources: ParsedSourceCacheSources,
|
||||
) -> Result<Self, AnyError> {
|
||||
log::debug!("Loading cached module analyzer.");
|
||||
|
@ -159,7 +159,7 @@ impl ParsedSourceCacheModuleAnalyzer {
|
|||
|
||||
fn from_connection(
|
||||
conn: Connection,
|
||||
cli_version: String,
|
||||
cli_version: &'static str,
|
||||
sources: ParsedSourceCacheSources,
|
||||
) -> Result<Self, AnyError> {
|
||||
initialize(&conn, cli_version)?;
|
||||
|
@ -287,7 +287,10 @@ impl deno_graph::ModuleAnalyzer for ParsedSourceCacheModuleAnalyzer {
|
|||
}
|
||||
}
|
||||
|
||||
fn initialize(conn: &Connection, cli_version: String) -> Result<(), AnyError> {
|
||||
fn initialize(
|
||||
conn: &Connection,
|
||||
cli_version: &'static str,
|
||||
) -> Result<(), AnyError> {
|
||||
let query = format!(
|
||||
"{INITIAL_PRAGMAS}
|
||||
-- INT doesn't store up to u64, so use TEXT for source_hash
|
||||
|
@ -314,7 +317,7 @@ fn initialize(conn: &Connection, cli_version: String) -> Result<(), AnyError> {
|
|||
|row| row.get(0),
|
||||
)
|
||||
.ok();
|
||||
if data_cli_version.as_deref() != Some(&cli_version) {
|
||||
if data_cli_version.as_deref() != Some(cli_version) {
|
||||
conn.execute("DELETE FROM moduleinfocache", params![])?;
|
||||
let mut stmt = conn
|
||||
.prepare("INSERT OR REPLACE INTO info (key, value) VALUES (?1, ?2)")?;
|
||||
|
@ -340,7 +343,7 @@ mod test {
|
|||
let conn = Connection::open_in_memory().unwrap();
|
||||
let cache = ParsedSourceCacheModuleAnalyzer::from_connection(
|
||||
conn,
|
||||
"1.0.0".to_string(),
|
||||
"1.0.0",
|
||||
Default::default(),
|
||||
)
|
||||
.unwrap();
|
||||
|
@ -403,7 +406,7 @@ mod test {
|
|||
let conn = cache.conn;
|
||||
let cache = ParsedSourceCacheModuleAnalyzer::from_connection(
|
||||
conn,
|
||||
"1.0.0".to_string(),
|
||||
"1.0.0",
|
||||
Default::default(),
|
||||
)
|
||||
.unwrap();
|
||||
|
@ -420,7 +423,7 @@ mod test {
|
|||
let conn = cache.conn;
|
||||
let cache = ParsedSourceCacheModuleAnalyzer::from_connection(
|
||||
conn,
|
||||
"1.0.1".to_string(),
|
||||
"1.0.1",
|
||||
Default::default(),
|
||||
)
|
||||
.unwrap();
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue