summaryrefslogtreecommitdiff
path: root/cli/cache/common.rs
diff options
context:
space:
mode:
authorDavid Sherret <dsherret@users.noreply.github.com>2022-07-12 18:58:39 -0400
committerGitHub <noreply@github.com>2022-07-12 18:58:39 -0400
commit0c87dd1e9898d7ac93e274d3611ee491a107d47a (patch)
treef626332706ccd12e0719f9b84d6b234d5483659b /cli/cache/common.rs
parent76107649804e674268becd693b7b2a954eecb3da (diff)
perf: use emit from swc instead of tsc (#15118)
Diffstat (limited to 'cli/cache/common.rs')
-rw-r--r--cli/cache/common.rs31
1 files changed, 31 insertions, 0 deletions
diff --git a/cli/cache/common.rs b/cli/cache/common.rs
new file mode 100644
index 000000000..c01c1ab9a
--- /dev/null
+++ b/cli/cache/common.rs
@@ -0,0 +1,31 @@
+// Copyright 2018-2022 the Deno authors. All rights reserved. MIT license.
+
+use deno_core::error::AnyError;
+use deno_runtime::deno_webstorage::rusqlite::Connection;
+
+/// Very fast non-cryptographically secure hash.
+pub fn fast_insecure_hash(bytes: &[u8]) -> u64 {
+ use std::hash::Hasher;
+ use twox_hash::XxHash64;
+
+ let mut hasher = XxHash64::default();
+ hasher.write(bytes);
+ hasher.finish()
+}
+
+/// Runs the common sqlite pragma.
+pub fn run_sqlite_pragma(conn: &Connection) -> Result<(), AnyError> {
+ // Enable write-ahead-logging and tweak some other stuff
+ let initial_pragmas = "
+ -- enable write-ahead-logging mode
+ PRAGMA journal_mode=WAL;
+ PRAGMA synchronous=NORMAL;
+ PRAGMA temp_store=memory;
+ PRAGMA page_size=4096;
+ PRAGMA mmap_size=6000000;
+ PRAGMA optimize;
+ ";
+
+ conn.execute_batch(initial_pragmas)?;
+ Ok(())
+}