Skip to content

Commit

Permalink
Remove unnecessary clones
Browse files Browse the repository at this point in the history
Removes unnecessary clones by:
  1) Removing the clone() call
  2) Borrowing the value instead
  3) Defering the clone() call on the item that needs to be cloned and
     not the whole containing datastructure
  • Loading branch information
StefanBossbaly committed Jan 4, 2024
1 parent c25c708 commit 08d9516
Show file tree
Hide file tree
Showing 36 changed files with 99 additions and 124 deletions.
4 changes: 2 additions & 2 deletions core/launcher/src/launcher_state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -59,9 +59,9 @@ impl LauncherState {
self.extn_client.clone().request(payload).await
}

pub async fn new(extn_client: ExtnClient) -> Result<LauncherState, RippleError> {
pub async fn new(mut extn_client: ExtnClient) -> Result<LauncherState, RippleError> {
let extn_message_response: Result<ExtnMessage, RippleError> =
extn_client.clone().request(Config::LauncherConfig).await;
extn_client.request(Config::LauncherConfig).await;
if let Ok(message) = extn_message_response {
if let Some(config) = message.payload.extract() {
return Ok(LauncherState {
Expand Down
19 changes: 7 additions & 12 deletions core/launcher/src/manager/app_launcher.rs
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ fn get_app_type(manifest: &AppManifest) -> Option<String> {
}

impl AppLauncherState {
fn get_active_instances(self, manifest: &AppManifest) -> usize {
fn get_active_instances(&self, manifest: &AppManifest) -> usize {
match get_app_type(manifest) {
Some(t) => self
.apps
Expand Down Expand Up @@ -203,7 +203,6 @@ impl AppLauncher {
debug!("set_state: container_id={}", container_id);
let mut final_resp = Ok(AppManagerResponse::None);
let item = state
.clone()
.app_launcher_state
.get_app_by_id(&container_id);

Expand All @@ -217,7 +216,6 @@ impl AppLauncher {
final_resp = Err(AppError::UnexpectedState);
} else {
state
.clone()
.app_launcher_state
.set_app_state(&container_id, lc_state);

Expand Down Expand Up @@ -258,11 +256,10 @@ impl AppLauncher {
} else {
// Container ID for app not found, check registered providers to
// see if it's a provider container ID.
let app_library_state = state.clone().config.app_library_state;
let resp = AppLibrary::get_provider(&app_library_state, container_id.to_string());
let app_library_state = &state.config.app_library_state;
let resp = AppLibrary::get_provider(app_library_state, container_id.to_string());
if let Some(provider) = resp {
final_resp = state
.clone()
.app_launcher_state
.get_app_by_id(&provider)
.map_or(Err(AppError::NotFound), |_| Ok(AppManagerResponse::None));
Expand Down Expand Up @@ -319,7 +316,7 @@ impl AppLauncher {
}

async fn check_retention_policy(state: &LauncherState) {
let policy = state.clone().config.retention_policy;
let policy = state.config.retention_policy.clone();
let mut app_count_exceeded = false;
let app_count = state.app_launcher_state.get_app_len() as u64;
if app_count > policy.max_retained {
Expand Down Expand Up @@ -373,7 +370,7 @@ impl AppLauncher {
}

fn get_oldest_removeable_app(state: &LauncherState) -> Option<String> {
let policy = state.clone().config.retention_policy;
let policy = state.config.retention_policy.clone();
let mut candidates = state.app_launcher_state.always_retained_apps(policy);

let count = candidates.len();
Expand Down Expand Up @@ -440,7 +437,6 @@ impl AppLauncher {

let id = app_id.to_string();
let timeout = state
.clone()
.config
.lifecycle_policy
.app_finished_timeout_ms;
Expand Down Expand Up @@ -630,7 +626,6 @@ impl AppLauncher {
return Err(AppError::NotSupported);
}
let instances = state
.clone()
.app_launcher_state
.get_active_instances(&app_manifest);
let bnrp = BrowserNameRequestParams {
Expand Down Expand Up @@ -695,7 +690,7 @@ impl AppLauncher {
h: launch_params.h,
};

let policy = state.clone().config.retention_policy;
let policy = state.config.retention_policy.clone();
let always_retained = policy
.always_retained
.iter()
Expand Down Expand Up @@ -740,7 +735,7 @@ impl AppLauncher {
Err(_) => return Err(AppError::IoError),
}
} else {
let timeout = state.clone().config.lifecycle_policy.app_ready_timeout_ms;
let timeout = state.config.lifecycle_policy.app_ready_timeout_ms;
let state_c = state.clone();
let app_id = request.app_id.clone();
let launch_time = app.launch_time;
Expand Down
4 changes: 2 additions & 2 deletions core/launcher/src/manager/container_manager.rs
Original file line number Diff line number Diff line change
Expand Up @@ -212,8 +212,8 @@ impl ContainerManager {

state.container_state.bring_stack_to_front(name);

let props = item.unwrap().clone();
let resp = ViewManager::set_position(state, props.clone().view_id, Position::Front).await;
let props = item.unwrap();
let resp = ViewManager::set_position(state, props.view_id, Position::Front).await;
if let Err(e) = resp {
debug!("bring_to_front: error: req_id={:?}", e);
return Err(ContainerError::General);
Expand Down
2 changes: 1 addition & 1 deletion core/launcher/src/manager/view_manager.rs
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,7 @@ impl ViewManager {
y: params.y,
w: params.w,
h: params.h,
properties: params.properties.clone().map(|r| r.get_browser_props()),
properties: params.properties.map(|r| r.get_browser_props()),
}))
.await;

Expand Down
4 changes: 2 additions & 2 deletions core/main/src/bootstrap/extn/load_extn_metadata_step.rs
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,8 @@ impl Bootstep<BootstrapState> for LoadExtensionMetadataStep {
async fn setup(&self, state: BootstrapState) -> Result<(), RippleError> {
debug!("Starting Extension Library step");
let manifest = state.platform_state.get_manifest();
let default_path = manifest.default_path.clone();
let default_extn = manifest.default_extension.clone();
let default_path = manifest.default_path;
let default_extn = manifest.default_extension;
let extn_paths: Vec<(String, ExtnManifestEntry)> = manifest
.extns
.into_iter()
Expand Down
10 changes: 5 additions & 5 deletions core/main/src/bootstrap/extn/load_extn_step.rs
Original file line number Diff line number Diff line change
Expand Up @@ -51,10 +51,10 @@ impl Bootstep<BootstrapState> for LoadExtensionsStep {
let mut device_channels: Vec<PreLoadedExtnChannel> = Vec::new();
let mut jsonrpsee_extns: Methods = Methods::new();
let mut open_rpcs: Vec<OpenRPCParser> = Vec::new();
let main_sender = state.clone().extn_state.get_sender();
let main_sender = state.extn_state.clone().get_sender();
for extn in loaded_extensions.iter() {
unsafe {
let path = extn.entry.clone().path;
let path = extn.entry.path.clone();
let library = &extn.library;
info!(
"path {} with # of symbols {}",
Expand Down Expand Up @@ -101,9 +101,9 @@ impl Bootstep<BootstrapState> for LoadExtensionsStep {
let extn_sender = ExtnSender::new(
main_sender.clone(),
extn_id,
extension.clone().uses,
extension.clone().fulfills,
extension.clone().config,
extension.uses,
extension.fulfills,
extension.config,
);
if let Some(open_rpc) = (builder.get_extended_capabilities)() {
match serde_json::from_str(&open_rpc) {
Expand Down
6 changes: 3 additions & 3 deletions core/main/src/bootstrap/extn/start_extn_channel_step.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ fn start_preloaded_channel(
) -> RippleResponse {
let client = state.platform_state.get_client();

if let Err(e) = state.clone().extn_state.start_channel(channel, client) {
if let Err(e) = state.extn_state.clone().start_channel(channel, client) {
error!("Error during Device channel bootstrap");
return Err(e);
}
Expand All @@ -58,7 +58,7 @@ impl Bootstep<BootstrapState> for StartExtnChannelsStep {
let mut device_channels = state.extn_state.device_channels.write().unwrap();
while let Some(device_channel) = device_channels.pop() {
let id = device_channel.extn_id.clone();
extn_ids.push(id.clone());
extn_ids.push(id);
if let Err(e) = start_preloaded_channel(&state, device_channel) {
error!("Error during Device channel bootstrap");
return Err(e);
Expand All @@ -70,7 +70,7 @@ impl Bootstep<BootstrapState> for StartExtnChannelsStep {
let mut deferred_channels = state.extn_state.deferred_channels.write().unwrap();
while let Some(deferred_channel) = deferred_channels.pop() {
let id = deferred_channel.extn_id.clone();
extn_ids.push(id.clone());
extn_ids.push(id);
if let Err(e) = start_preloaded_channel(&state, deferred_channel) {
error!("Error during channel bootstrap");
return Err(e);
Expand Down
6 changes: 3 additions & 3 deletions core/main/src/bootstrap/setup_extn_client_step.rs
Original file line number Diff line number Diff line change
Expand Up @@ -52,15 +52,15 @@ impl Bootstep<BootstrapState> for SetupExtnClientStep {
client.add_request_processor(ConfigRequestProcessor::new(state.platform_state.clone()));
client.add_request_processor(PinProcessor::new(state.platform_state.clone()));
client.add_request_processor(KeyboardProcessor::new(state.platform_state.clone()));
client.add_event_processor(ExtnStatusProcessor::new(state.clone().extn_state));
client.add_event_processor(ExtnStatusProcessor::new(state.extn_state.clone()));
client.add_event_processor(AppEventsProcessor::new(state.platform_state.clone()));
client.add_request_processor(StorageManagerProcessor::new(state.platform_state.clone()));
client.add_request_processor(StoreUserGrantsProcessor::new(state.platform_state.clone()));
client.add_request_processor(StorePrivacySettingsProcessor::new(
state.platform_state.clone(),
));
client.add_request_processor(AuthorizedInfoProcessor::new(state.clone().platform_state));
client.add_request_processor(AccountLinkProcessor::new(state.clone().platform_state));
client.add_request_processor(AuthorizedInfoProcessor::new(state.platform_state.clone()));
client.add_request_processor(AccountLinkProcessor::new(state.platform_state.clone()));
client.add_request_processor(SettingsProcessor::new(state.platform_state.clone()));
client.add_request_processor(MetricsProcessor::new(state.platform_state.clone()));
client.add_request_processor(OpMetricsProcessor::new(state.platform_state.clone()));
Expand Down
2 changes: 1 addition & 1 deletion core/main/src/firebolt/handlers/account_rpc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ impl AccountServer for AccountImpl {
async fn session(&self, _ctx: CallContext, a_t_r: AccountSessionTokenRequest) -> RpcResult<()> {
self.platform_state
.session_state
.insert_session_token(a_t_r.clone().token);
.insert_session_token(a_t_r.token.clone());
let resp = self
.platform_state
.get_client()
Expand Down
4 changes: 2 additions & 2 deletions core/main/src/firebolt/handlers/device_rpc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -304,7 +304,7 @@ impl DeviceServer for DeviceImpl {
}

async fn uid(&self, ctx: CallContext) -> RpcResult<String> {
get_uid(&self.state, ctx.app_id.clone()).await
get_uid(&self.state, ctx.app_id).await
}

async fn platform(&self, _ctx: CallContext) -> RpcResult<String> {
Expand All @@ -320,7 +320,7 @@ impl DeviceServer for DeviceImpl {
);
os.readable = format!("Firebolt OS v{}", env!("CARGO_PKG_VERSION"));

let firmware = self.firmware_info(ctx.clone()).await?;
let firmware = self.firmware_info(ctx).await?;

let open_rpc_state = self.state.clone().open_rpc_state;
let api = open_rpc_state.get_open_rpc().info;
Expand Down
6 changes: 3 additions & 3 deletions core/main/src/firebolt/handlers/voice_guidance_rpc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -261,9 +261,9 @@ impl VoiceguidanceServer for VoiceguidanceImpl {
request: ListenRequest,
) -> RpcResult<ListenerResponse> {
voice_guidance_settings_enabled_changed(
&self.state.clone(),
&ctx.clone(),
&request.clone(),
&self.state,
&ctx,
&request,
Some(Box::new(VGEnabledEventDecorator {})),
)
.await
Expand Down
2 changes: 1 addition & 1 deletion core/main/src/processor/app_events_processor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ impl ExtnEventProcessor for AppEventsProcessor {
) -> Option<bool> {
match extracted_message.clone() {
AppEventRequest::Emit(event) => {
if let Some(app_id) = event.clone().app_id {
if let Some(app_id) = event.app_id {
let event_name = &event.event_name;
let result = &event.result;
AppEvents::emit_to_app(&state, app_id, event_name, result).await;
Expand Down
2 changes: 1 addition & 1 deletion core/main/src/processor/authorized_info_processor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ impl ExtnRequestProcessor for AuthorizedInfoProcessor {
msg: ExtnMessage,
extracted_message: Self::VALUE,
) -> bool {
match extracted_message.clone() {
match extracted_message {
CapsRequest::Permitted(app_id, request) => {
let result = state
.cap_state
Expand Down
12 changes: 6 additions & 6 deletions core/main/src/processor/config_processor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ impl ExtnRequestProcessor for ConfigRequestProcessor {
let config = LauncherConfig {
lifecycle_policy: device_manifest.get_lifecycle_policy(),
retention_policy: device_manifest.get_retention_policy(),
app_library_state: state.clone().app_library_state,
app_library_state: state.app_library_state.clone(),
};
if let ExtnPayload::Response(r) = config.get_extn_payload() {
r
Expand All @@ -107,22 +107,22 @@ impl ExtnRequestProcessor for ConfigRequestProcessor {
ExtnResponse::DefaultApp(state.app_library_state.get_default_app().unwrap())
}
Config::SavedDir => {
ExtnResponse::String(device_manifest.clone().configuration.saved_dir)
ExtnResponse::String(device_manifest.configuration.saved_dir.clone())
}
Config::FormFactor => ExtnResponse::String(device_manifest.get_form_factor()),
Config::DistributorExperienceId => {
ExtnResponse::String(device_manifest.get_distributor_experience_id())
}
Config::DistributorServices => {
if let Some(v) = device_manifest.clone().configuration.distributor_services {
ExtnResponse::Value(v)
if let Some(v) = &device_manifest.configuration.distributor_services {
ExtnResponse::Value(v.clone())
} else {
ExtnResponse::None(())
}
}
Config::IdSalt => {
if let Some(v) = device_manifest.clone().configuration.distribution_id_salt {
ExtnResponse::Config(ConfigResponse::IdSalt(v))
if let Some(v) = &device_manifest.configuration.distribution_id_salt {
ExtnResponse::Config(ConfigResponse::IdSalt(v.clone()))
} else {
ExtnResponse::None(())
}
Expand Down
2 changes: 1 addition & 1 deletion core/main/src/processor/metrics_processor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -259,7 +259,7 @@ impl ExtnRequestProcessor for OpMetricsProcessor {
msg: ExtnMessage,
extracted_message: Self::VALUE,
) -> bool {
let requestor = msg.clone().requestor.to_string();
let requestor = msg.requestor.to_string();
match extracted_message {
OperationalMetricRequest::Subscribe => state
.metrics
Expand Down
12 changes: 6 additions & 6 deletions core/main/src/processor/settings_processor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ impl SettingsProcessor {
let mut settings = HashMap::default();
for sk in request.keys.clone() {
use SettingKey::*;
let val = match sk.clone() {
let val = match sk {
VoiceGuidanceEnabled => {
let enabled = voice_guidance_settings_enabled(state)
.await
Expand Down Expand Up @@ -191,15 +191,15 @@ impl SettingsProcessor {
request: SettingsRequestParam,
) -> bool {
let mut resp = true;
let ctx = request.context.clone();
let ctx = &request.context;
debug!("Incoming subscribe request");
for key in request.keys.clone() {
for key in &request.keys {
debug!("Checking Key {:?}", key);
match key {
SettingKey::VoiceGuidanceEnabled => {
if voice_guidance_settings_enabled_changed(
state,
&ctx,
ctx,
&ListenRequest { listen: true },
Some(Box::new(SettingsChangeEventDecorator {
request: request.clone(),
Expand Down Expand Up @@ -231,7 +231,7 @@ impl SettingsProcessor {
if PrivacyImpl::listen_content_policy_changed(
state,
true,
&ctx,
ctx,
EVENT_ALLOW_PERSONALIZATION_CHANGED,
Some(ContentListenRequest {
listen: true,
Expand All @@ -250,7 +250,7 @@ impl SettingsProcessor {
if PrivacyImpl::listen_content_policy_changed(
state,
true,
&ctx,
ctx,
EVENT_ALLOW_WATCH_HISTORY_CHANGED,
Some(ContentListenRequest {
listen: true,
Expand Down
Loading

0 comments on commit 08d9516

Please sign in to comment.