Browse Source

Bunch of refactoring & optimizations

iorveth 4 years ago
parent
commit
a1615330bd

+ 1 - 1
runtime-modules/content-directory/src/lib.rs

@@ -1595,7 +1595,7 @@ impl<T: Trait> Module<T> {
         Self::ensure_schema_id_is_not_added(&entity, schema_id)?;
 
         let class_schema_opt = class.schemas.get(schema_id as usize);
-        let schema_prop_ids = class_schema_opt.unwrap().properties.clone();
+        let schema_prop_ids = &class_schema_opt.unwrap().properties;
 
         let current_entity_values = entity.values.clone();
         let mut appended_entity_values = entity.values;

+ 3 - 4
runtime-modules/content-directory/src/mock.rs

@@ -260,10 +260,9 @@ pub fn with_test_externalities<R, F: FnOnce() -> R>(f: F) -> R {
 }
 
 impl Property {
-    pub fn required(&self) -> Property {
-        let mut new_self = self.clone();
-        new_self.required = true;
-        new_self
+    pub fn required(self) -> Self {
+        self.required = true;
+        self
     }
 }
 

+ 3 - 6
runtime-modules/content-directory/src/operations.rs

@@ -70,8 +70,7 @@ pub fn parametrized_entity_to_entity_id(
         ParameterizedEntity::ExistingEntity(entity_id) => Ok(entity_id),
         ParameterizedEntity::InternalEntityJustAdded(op_index_u32) => {
             let op_index = op_index_u32 as usize;
-            if created_entities.contains_key(&op_index) {
-                let entity_id = created_entities.get(&op_index).unwrap();
+            if let Some(entity_id) = created_entities.get(&op_index) {
                 Ok(*entity_id)
             } else {
                 Err("EntityNotCreatedByOperation")
@@ -94,8 +93,7 @@ pub fn parametrized_property_values_to_property_values<T: Trait>(
             ) => {
                 // Verify that referenced entity was indeed created created
                 let op_index = entity_created_in_operation_index as usize;
-                if created_entities.contains_key(&op_index) {
-                    let entity_id = created_entities.get(&op_index).unwrap();
+                if let Some(entity_id) = created_entities.get(&op_index) {
                     PropertyValue::Reference(*entity_id)
                 } else {
                     return Err("EntityNotCreatedByOperation");
@@ -111,8 +109,7 @@ pub fn parametrized_property_values_to_property_values<T: Trait>(
                             entity_created_in_operation_index,
                         ) => {
                             let op_index = entity_created_in_operation_index as usize;
-                            if created_entities.contains_key(&op_index) {
-                                let entity_id = created_entities.get(&op_index).unwrap();
+                            if let Some(entity_id) = created_entities.get(&op_index) {
                                 entities.push(*entity_id);
                             } else {
                                 return Err("EntityNotCreatedByOperation");