summaryrefslogtreecommitdiff
path: root/src/util
diff options
context:
space:
mode:
authorLaurenz <laurmaedje@gmail.com>2022-09-21 17:50:58 +0200
committerLaurenz <laurmaedje@gmail.com>2022-09-21 20:25:57 +0200
commitddd3b6a82b8c0353c942bfba8b89ca5476eedc58 (patch)
treea64c350f0f1f82152ff18cfb02fbfdbf39292672 /src/util
parent3760748fddd3b793c79c370398a9d4a3fc5afc04 (diff)
Tracked memoization
Diffstat (limited to 'src/util')
-rw-r--r--src/util/buffer.rs2
-rw-r--r--src/util/hash.rs63
-rw-r--r--src/util/mod.rs2
3 files changed, 1 insertions, 66 deletions
diff --git a/src/util/buffer.rs b/src/util/buffer.rs
index daee86f9..766b2084 100644
--- a/src/util/buffer.rs
+++ b/src/util/buffer.rs
@@ -2,7 +2,7 @@ use std::fmt::{self, Debug, Formatter};
use std::ops::Deref;
use std::sync::Arc;
-use super::Prehashed;
+use comemo::Prehashed;
/// A shared buffer that is cheap to clone and hash.
#[derive(Clone, Hash, Eq, PartialEq)]
diff --git a/src/util/hash.rs b/src/util/hash.rs
deleted file mode 100644
index 79455918..00000000
--- a/src/util/hash.rs
+++ /dev/null
@@ -1,63 +0,0 @@
-use std::any::Any;
-use std::fmt::{self, Debug, Formatter};
-use std::hash::{Hash, Hasher};
-use std::ops::Deref;
-
-/// A wrapper around a type that precomputes its hash.
-#[derive(Copy, Clone)]
-pub struct Prehashed<T: ?Sized> {
- /// The precomputed hash.
- hash: u64,
- /// The wrapped item.
- item: T,
-}
-
-impl<T: Hash + 'static> Prehashed<T> {
- /// Compute an item's hash and wrap it.
- pub fn new(item: T) -> Self {
- Self {
- hash: {
- // Also hash the TypeId because the type might be converted
- // through an unsized coercion.
- let mut state = fxhash::FxHasher64::default();
- item.type_id().hash(&mut state);
- item.hash(&mut state);
- state.finish()
- },
- item,
- }
- }
-
- /// Return the wrapped value.
- pub fn into_iter(self) -> T {
- self.item
- }
-}
-
-impl<T: ?Sized> Deref for Prehashed<T> {
- type Target = T;
-
- fn deref(&self) -> &Self::Target {
- &self.item
- }
-}
-
-impl<T: Debug + ?Sized> Debug for Prehashed<T> {
- fn fmt(&self, f: &mut Formatter) -> fmt::Result {
- self.item.fmt(f)
- }
-}
-
-impl<T: ?Sized> Hash for Prehashed<T> {
- fn hash<H: Hasher>(&self, state: &mut H) {
- state.write_u64(self.hash);
- }
-}
-
-impl<T: Eq + ?Sized> Eq for Prehashed<T> {}
-
-impl<T: ?Sized> PartialEq for Prehashed<T> {
- fn eq(&self, other: &Self) -> bool {
- self.hash == other.hash
- }
-}
diff --git a/src/util/mod.rs b/src/util/mod.rs
index 4a48b1d3..d549fc5f 100644
--- a/src/util/mod.rs
+++ b/src/util/mod.rs
@@ -3,11 +3,9 @@
#[macro_use]
mod eco;
mod buffer;
-mod hash;
pub use buffer::Buffer;
pub use eco::EcoString;
-pub use hash::Prehashed;
use std::any::TypeId;
use std::fmt::{self, Debug, Formatter};