mirror of
https://github.com/facebook/sapling.git
synced 2024-12-28 23:54:12 +03:00
revisionstore: prefetch takes &[Key] instead of Vec<Key>
Summary: This can prevent potential moves and clones on the caller of prefetch. Reviewed By: quark-zju Differential Revision: D19518697 fbshipit-source-id: 63839fc3f4bb9ca420e290eabaffb481a3584f7b
This commit is contained in:
parent
83cdc441c8
commit
b6589bde84
@ -52,7 +52,7 @@ impl<T: DataStore + RemoteDataStore> manifest_tree::TreeStore for ManifestStore<
|
||||
}
|
||||
|
||||
fn prefetch(&self, keys: Vec<Key>) -> Result<()> {
|
||||
self.underlying.prefetch(keys)
|
||||
self.underlying.prefetch(&keys)
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -200,7 +200,7 @@ impl<T: RemoteDataStore + ?Sized> RemoteDataStorePyExt for T {
|
||||
.iter(py)
|
||||
.map(|tuple| from_tuple_to_key(py, &tuple))
|
||||
.collect::<PyResult<Vec<Key>>>()?;
|
||||
self.prefetch(keys).map_pyerr(py)?;
|
||||
self.prefetch(&keys).map_pyerr(py)?;
|
||||
Ok(Python::None(py))
|
||||
}
|
||||
}
|
||||
|
@ -192,7 +192,7 @@ impl<T: RemoteHistoryStore + ?Sized> RemoteHistoryStorePyExt for T {
|
||||
.iter(py)
|
||||
.map(|tuple| from_tuple_to_key(py, &tuple))
|
||||
.collect::<PyResult<Vec<Key>>>()?;
|
||||
self.prefetch(keys).map_pyerr(py)?;
|
||||
self.prefetch(&keys).map_pyerr(py)?;
|
||||
Ok(Python::None(py))
|
||||
}
|
||||
}
|
||||
|
@ -692,7 +692,7 @@ struct PyRemoteStore {
|
||||
}
|
||||
|
||||
impl PyRemoteStore {
|
||||
fn prefetch(&self, keys: Vec<Key>) -> Result<()> {
|
||||
fn prefetch(&self, keys: &[Key]) -> Result<()> {
|
||||
let gil = Python::acquire_gil();
|
||||
let py = gil.python();
|
||||
|
||||
@ -745,7 +745,7 @@ impl RemoteStore for PyRemoteStore {
|
||||
}
|
||||
|
||||
impl RemoteDataStore for PyRemoteDataStore {
|
||||
fn prefetch(&self, keys: Vec<Key>) -> Result<()> {
|
||||
fn prefetch(&self, keys: &[Key]) -> Result<()> {
|
||||
self.0.prefetch(keys)
|
||||
}
|
||||
}
|
||||
@ -756,7 +756,7 @@ impl DataStore for PyRemoteDataStore {
|
||||
}
|
||||
|
||||
fn get_delta(&self, key: &Key) -> Result<Option<Delta>> {
|
||||
match self.prefetch(vec![key.clone()]) {
|
||||
match self.prefetch(&[key.clone()]) {
|
||||
Ok(()) => self
|
||||
.0
|
||||
.inner
|
||||
@ -770,7 +770,7 @@ impl DataStore for PyRemoteDataStore {
|
||||
}
|
||||
|
||||
fn get_delta_chain(&self, key: &Key) -> Result<Option<Vec<Delta>>> {
|
||||
match self.prefetch(vec![key.clone()]) {
|
||||
match self.prefetch(&[key.clone()]) {
|
||||
Ok(()) => self
|
||||
.0
|
||||
.inner
|
||||
@ -784,7 +784,7 @@ impl DataStore for PyRemoteDataStore {
|
||||
}
|
||||
|
||||
fn get_meta(&self, key: &Key) -> Result<Option<Metadata>> {
|
||||
match self.prefetch(vec![key.clone()]) {
|
||||
match self.prefetch(&[key.clone()]) {
|
||||
Ok(()) => self
|
||||
.0
|
||||
.inner
|
||||
@ -805,14 +805,14 @@ impl LocalStore for PyRemoteDataStore {
|
||||
}
|
||||
|
||||
impl RemoteHistoryStore for PyRemoteHistoryStore {
|
||||
fn prefetch(&self, keys: Vec<Key>) -> Result<()> {
|
||||
fn prefetch(&self, keys: &[Key]) -> Result<()> {
|
||||
self.0.prefetch(keys)
|
||||
}
|
||||
}
|
||||
|
||||
impl HistoryStore for PyRemoteHistoryStore {
|
||||
fn get_node_info(&self, key: &Key) -> Result<Option<NodeInfo>> {
|
||||
match self.prefetch(vec![key.clone()]) {
|
||||
match self.prefetch(&[key.clone()]) {
|
||||
Ok(()) => self
|
||||
.0
|
||||
.inner
|
||||
|
@ -147,7 +147,7 @@ impl DataStore for PythonDataStore {
|
||||
}
|
||||
|
||||
impl RemoteDataStore for PythonDataStore {
|
||||
fn prefetch(&self, keys: Vec<Key>) -> Result<()> {
|
||||
fn prefetch(&self, keys: &[Key]) -> Result<()> {
|
||||
let gil = Python::acquire_gil();
|
||||
let py = gil.python();
|
||||
let keys = keys
|
||||
|
@ -68,13 +68,13 @@ impl DataStore for ContentStore {
|
||||
}
|
||||
|
||||
impl RemoteDataStore for ContentStore {
|
||||
fn prefetch(&self, keys: Vec<Key>) -> Result<()> {
|
||||
fn prefetch(&self, keys: &[Key]) -> Result<()> {
|
||||
if let Some(remote_store) = self.inner.remote_store.as_ref() {
|
||||
let missing = self.get_missing(&keys)?;
|
||||
let missing = self.get_missing(keys)?;
|
||||
if missing == vec![] {
|
||||
Ok(())
|
||||
} else {
|
||||
remote_store.prefetch(missing)
|
||||
remote_store.prefetch(&missing)
|
||||
}
|
||||
} else {
|
||||
// There is no remote store, let's pretend everything is fine.
|
||||
|
@ -49,7 +49,7 @@ pub trait RemoteDataStore: DataStore + Send + Sync {
|
||||
/// When implemented on a pure remote store, like the `EdenApi`, the method will always fetch
|
||||
/// everything that was asked. On a higher level store, such as the `ContentStore`, this will
|
||||
/// avoid fetching data that is already present locally.
|
||||
fn prefetch(&self, keys: Vec<Key>) -> Result<()>;
|
||||
fn prefetch(&self, keys: &[Key]) -> Result<()>;
|
||||
}
|
||||
|
||||
pub trait MutableDeltaStore: DataStore + Send + Sync {
|
||||
@ -77,7 +77,7 @@ impl<T: DataStore + ?Sized, U: Deref<Target = T> + Send + Sync> DataStore for U
|
||||
/// Implement `RemoteDataStore` for all types that can be `Deref` into a `RemoteDataStore`. This
|
||||
/// includes all the smart pointers like `Box`, `Rc`, `Arc`.
|
||||
impl<T: RemoteDataStore + ?Sized, U: Deref<Target = T> + Send + Sync> RemoteDataStore for U {
|
||||
fn prefetch(&self, keys: Vec<Key>) -> Result<()> {
|
||||
fn prefetch(&self, keys: &[Key]) -> Result<()> {
|
||||
T::prefetch(self, keys)
|
||||
}
|
||||
}
|
||||
|
@ -75,11 +75,11 @@ struct EdenApiRemoteDataStore {
|
||||
}
|
||||
|
||||
impl RemoteDataStore for EdenApiRemoteDataStore {
|
||||
fn prefetch(&self, keys: Vec<Key>) -> Result<()> {
|
||||
fn prefetch(&self, keys: &[Key]) -> Result<()> {
|
||||
let edenapi = &self.inner.edenapi;
|
||||
let (entries, _) = match edenapi.kind {
|
||||
EdenApiRemoteStoreKind::File => edenapi.edenapi.get_files(keys, None)?,
|
||||
EdenApiRemoteStoreKind::Tree => edenapi.edenapi.get_trees(keys, None)?,
|
||||
EdenApiRemoteStoreKind::File => edenapi.edenapi.get_files(keys.to_vec(), None)?,
|
||||
EdenApiRemoteStoreKind::Tree => edenapi.edenapi.get_trees(keys.to_vec(), None)?,
|
||||
};
|
||||
for entry in entries {
|
||||
let key = entry.0.clone();
|
||||
@ -105,21 +105,21 @@ impl DataStore for EdenApiRemoteDataStore {
|
||||
}
|
||||
|
||||
fn get_delta(&self, key: &Key) -> Result<Option<Delta>> {
|
||||
match self.prefetch(vec![key.clone()]) {
|
||||
match self.prefetch(&[key.clone()]) {
|
||||
Ok(()) => self.inner.store.get_delta(key),
|
||||
Err(_) => Ok(None),
|
||||
}
|
||||
}
|
||||
|
||||
fn get_delta_chain(&self, key: &Key) -> Result<Option<Vec<Delta>>> {
|
||||
match self.prefetch(vec![key.clone()]) {
|
||||
match self.prefetch(&[key.clone()]) {
|
||||
Ok(()) => self.inner.store.get_delta_chain(key),
|
||||
Err(_) => Ok(None),
|
||||
}
|
||||
}
|
||||
|
||||
fn get_meta(&self, key: &Key) -> Result<Option<Metadata>> {
|
||||
match self.prefetch(vec![key.clone()]) {
|
||||
match self.prefetch(&[key.clone()]) {
|
||||
Ok(()) => self.inner.store.get_meta(key),
|
||||
Err(_) => Ok(None),
|
||||
}
|
||||
|
@ -35,7 +35,7 @@ pub trait RemoteHistoryStore: HistoryStore + Send + Sync {
|
||||
/// When implemented on a pure remote store, like the `EdenApi`, the method will always fetch
|
||||
/// everything that was asked. On a higher level store, such as the `MetadataStore`, this will
|
||||
/// avoid fetching data that is already present locally.
|
||||
fn prefetch(&self, keys: Vec<Key>) -> Result<()>;
|
||||
fn prefetch(&self, keys: &[Key]) -> Result<()>;
|
||||
}
|
||||
|
||||
/// Implement `HistoryStore` for all types that can be `Deref` into a `HistoryStore`.
|
||||
|
@ -56,13 +56,13 @@ impl HistoryStore for MetadataStore {
|
||||
}
|
||||
|
||||
impl RemoteHistoryStore for MetadataStore {
|
||||
fn prefetch(&self, keys: Vec<Key>) -> Result<()> {
|
||||
fn prefetch(&self, keys: &[Key]) -> Result<()> {
|
||||
if let Some(remote_store) = self.inner.remote_store.as_ref() {
|
||||
let missing = self.get_missing(&keys)?;
|
||||
if missing == vec![] {
|
||||
Ok(())
|
||||
} else {
|
||||
remote_store.prefetch(missing)
|
||||
remote_store.prefetch(&missing)
|
||||
}
|
||||
} else {
|
||||
// There is no remote store, let's pretend everything is fine.
|
||||
|
@ -76,13 +76,13 @@ struct FakeRemoteDataStore {
|
||||
}
|
||||
|
||||
impl RemoteDataStore for FakeRemoteDataStore {
|
||||
fn prefetch(&self, keys: Vec<Key>) -> Result<()> {
|
||||
fn prefetch(&self, keys: &[Key]) -> Result<()> {
|
||||
for k in keys {
|
||||
let data = self.map.get(&k).ok_or_else(|| Error::msg("Not found"))?;
|
||||
let delta = Delta {
|
||||
data: data.clone(),
|
||||
base: None,
|
||||
key: k,
|
||||
key: k.clone(),
|
||||
};
|
||||
self.store.add(&delta, &Default::default())?;
|
||||
}
|
||||
@ -97,21 +97,21 @@ impl DataStore for FakeRemoteDataStore {
|
||||
}
|
||||
|
||||
fn get_delta(&self, key: &Key) -> Result<Option<Delta>> {
|
||||
match self.prefetch(vec![key.clone()]) {
|
||||
match self.prefetch(&[key.clone()]) {
|
||||
Err(_) => Ok(None),
|
||||
Ok(()) => self.store.get_delta(key),
|
||||
}
|
||||
}
|
||||
|
||||
fn get_delta_chain(&self, key: &Key) -> Result<Option<Vec<Delta>>> {
|
||||
match self.prefetch(vec![key.clone()]) {
|
||||
match self.prefetch(&[key.clone()]) {
|
||||
Err(_) => Ok(None),
|
||||
Ok(()) => self.store.get_delta_chain(key),
|
||||
}
|
||||
}
|
||||
|
||||
fn get_meta(&self, key: &Key) -> Result<Option<Metadata>> {
|
||||
match self.prefetch(vec![key.clone()]) {
|
||||
match self.prefetch(&[key.clone()]) {
|
||||
Err(_) => Ok(None),
|
||||
Ok(()) => self.store.get_meta(key),
|
||||
}
|
||||
@ -130,7 +130,7 @@ struct FakeRemoteHistoryStore {
|
||||
}
|
||||
|
||||
impl RemoteHistoryStore for FakeRemoteHistoryStore {
|
||||
fn prefetch(&self, keys: Vec<Key>) -> Result<()> {
|
||||
fn prefetch(&self, keys: &[Key]) -> Result<()> {
|
||||
for k in keys {
|
||||
self.store
|
||||
.add(&k, self.map.get(&k).ok_or_else(|| Error::msg("Not found"))?)?
|
||||
@ -142,7 +142,7 @@ impl RemoteHistoryStore for FakeRemoteHistoryStore {
|
||||
|
||||
impl HistoryStore for FakeRemoteHistoryStore {
|
||||
fn get_node_info(&self, key: &Key) -> Result<Option<NodeInfo>> {
|
||||
match self.prefetch(vec![key.clone()]) {
|
||||
match self.prefetch(&[key.clone()]) {
|
||||
Err(_) => Ok(None),
|
||||
Ok(()) => self.store.get_node_info(key),
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user