瀏覽代碼

Fix clippy nits.

Kestrel 2 年之前
父節點
當前提交
3cec9bad45
共有 1 個文件被更改,包括 4 次插入14 次删除
  1. 4 14
      microrm/src/query.rs

+ 4 - 14
microrm/src/query.rs

@@ -100,15 +100,10 @@ impl<'l> QueryInterface<'l> {
     ) -> Return {
         let mut cache = self.cache.lock().expect("Couldn't acquire cache?");
         let key = (context, ty, NO_HASH);
-        if !cache.contains_key(&key) {
-            cache.insert(key, create());
-        }
-        let mut query = cache
-            .get_mut(&key)
-            .expect("Just-inserted item not in cache?");
+        let query = cache.entry(key).or_insert_with(create);
 
         query.reset().expect("Couldn't reset query");
-        with(&mut query)
+        with(query)
     }
 
     fn cached_query_column<Column: crate::model::EntityColumns, Return>(
@@ -127,15 +122,10 @@ impl<'l> QueryInterface<'l> {
 
         let mut cache = self.cache.lock().expect("Couldn't acquire cache?");
         let key = (context, ty, hash);
-        if !cache.contains_key(&key) {
-            cache.insert(key, create());
-        }
-        let mut query = cache
-            .get_mut(&key)
-            .expect("Just-inserted item not in cache?");
+        let query = cache.entry(key).or_insert_with(create);
 
         query.reset().expect("Couldn't reset query");
-        with(&mut query)
+        with(query)
     }
 
     /// Search for an entity by a property