We can reduce cloning in Class::from_object/from_value by passing it as a reference. If object is not an instance of the desired class, we avoid the cloning all together. If so, we can simply clone the refernce.
In the current implementation we first clone the value before checking. If we need to check if a value is of certain class many times it's very unnecessary, for instance:
if let Some(a) = Class::<A>::from_value(value.clone()){
//use value
}
if let Some(a) = Class::<B>::from_value(value.clone()){
//use value
}
if let Some(a) = Class::<C>::from_value(value.clone()){
//use value
}
Can now be reduced to:
if let Some(a) = Class::<A>::from_value(&value){
//use value
}
if let Some(a) = Class::<B>::from_value(&value){
//use value
}
if let Some(a) = Class::<C>::from_value(&value){
//use value
}
We can reduce cloning in Class::from_object/from_value by passing it as a reference. If object is not an instance of the desired class, we avoid the cloning all together. If so, we can simply clone the refernce.
In the current implementation we first clone the value before checking. If we need to check if a value is of certain class many times it's very unnecessary, for instance:
Can now be reduced to: