From 02a163a10fbb88d81dcbe10b98714d55c4330747 Mon Sep 17 00:00:00 2001 From: Nick Alexander Date: Mon, 2 Jul 2018 09:34:57 -0700 Subject: [PATCH] Part 2: Use `ValueRc` in `InternSet`. We haven't observed performance issues using `Arc` instead of `Rc`, and we want to be able to include things that are interned (including, soon, `TempId` instances) in errors coming out of the transactor. (And `Rc` isn't `Sync`, so it can't be included in errors directly.) --- db/src/internal_types.rs | 20 ++++++++++---------- db/src/tx.rs | 6 ++---- edn/src/intern_set.rs | 16 +++++++++------- 3 files changed, 21 insertions(+), 21 deletions(-) diff --git a/db/src/internal_types.rs b/db/src/internal_types.rs index 72dda98d..9e323d61 100644 --- a/db/src/internal_types.rs +++ b/db/src/internal_types.rs @@ -17,7 +17,6 @@ use std::collections::{ BTreeSet, HashMap, }; -use std::rc::Rc; use mentat_core::KnownEntid; @@ -27,6 +26,14 @@ use edn; use edn::{ SpannedValue, ValueAndSpan, + ValueRc, +}; +use edn::entities; +use edn::entities::{ + EntityPlace, + OpType, + TempId, + TxFunction, }; use errors; @@ -47,13 +54,6 @@ use types::{ TypedValue, ValueType, }; -use edn::entities; -use edn::entities::{ - EntityPlace, - OpType, - TempId, - TxFunction, -}; impl TransactableValue for ValueAndSpan { fn into_typed_value(self, schema: &Schema, value_type: ValueType) -> Result { @@ -150,10 +150,10 @@ use self::Either::*; pub type KnownEntidOr = Either; pub type TypedValueOr = Either; -pub type TempIdHandle = Rc; +pub type TempIdHandle = ValueRc; pub type TempIdMap = HashMap; -pub type LookupRef = Rc; +pub type LookupRef = ValueRc; /// Internal representation of an entid on its way to resolution. We either have the simple case (a /// numeric entid), a lookup-ref that still needs to be resolved (an atomized [a v] pair), or a temp diff --git a/db/src/tx.rs b/db/src/tx.rs index c4ce8321..c00b6a95 100644 --- a/db/src/tx.rs +++ b/db/src/tx.rs @@ -56,9 +56,6 @@ use std::collections::{ use std::iter::{ once, }; -use std::rc::{ - Rc, -}; use db; use db::{ @@ -68,6 +65,7 @@ use db::{ use edn::{ InternSet, Keyword, + ValueRc, }; use entids; use errors; @@ -303,7 +301,7 @@ impl<'conn, 'a, W> Tx<'conn, 'a, W> where W: TransactWatcher { Ok(self.lookup_refs.intern((lr_a, lr_typed_value))) } - fn intern_temp_id(&mut self, temp_id: TempId) -> Rc { + fn intern_temp_id(&mut self, temp_id: TempId) -> ValueRc { self.temp_ids.intern(temp_id) } diff --git a/edn/src/intern_set.rs b/edn/src/intern_set.rs index c8c7418f..acec137e 100644 --- a/edn/src/intern_set.rs +++ b/edn/src/intern_set.rs @@ -12,7 +12,10 @@ use std::collections::HashSet; use std::hash::Hash; -use std::rc::Rc; + +use ::{ + ValueRc, +}; /// An `InternSet` allows to "intern" some potentially large values, maintaining a single value /// instance owned by the `InternSet` and leaving consumers with lightweight ref-counted handles to @@ -23,7 +26,7 @@ use std::rc::Rc; /// See https://en.wikipedia.org/wiki/String_interning for discussion. #[derive(Clone, Debug, Default, Eq, PartialEq)] pub struct InternSet where T: Eq + Hash { - pub inner: HashSet>, + pub inner: HashSet>, } impl InternSet where T: Eq + Hash { @@ -40,13 +43,12 @@ impl InternSet where T: Eq + Hash { /// Intern a value, providing a ref-counted handle to the interned value. /// /// ``` - /// use std::rc::Rc; - /// use edn::intern_set::InternSet; + /// use edn::{InternSet, ValueRc}; /// /// let mut s = InternSet::new(); /// /// let one = "foo".to_string(); - /// let two = Rc::new("foo".to_string()); + /// let two = ValueRc::new("foo".to_string()); /// /// let out_one = s.intern(one); /// assert_eq!(out_one, two); @@ -57,8 +59,8 @@ impl InternSet where T: Eq + Hash { /// assert_eq!(1, s.inner.len()); /// // assert!(&out_one.ptr_eq(&out_two)); // Nightly-only. /// ``` - pub fn intern>>(&mut self, value: R) -> Rc { - let key: Rc = value.into(); + pub fn intern>>(&mut self, value: R) -> ValueRc { + let key: ValueRc = value.into(); if self.inner.insert(key.clone()) { key } else {