From bce067d411278192a340d4fc19860af9a2a5e01c Mon Sep 17 00:00:00 2001 From: Deokhyun Kim Date: Wed, 2 Jan 2019 11:02:30 +0900 Subject: [PATCH] Improve efficiency of using g_array_index Change-Id: Ia2c56e65d5900f67d0089290663cfb0c95bb6a85 Signed-off-by: Deokhyun Kim --- bt-api/bt-adapter.c | 6 ++--- bt-api/bt-avrcp.c | 20 ++++++++--------- .../services/bt-request-handler.c | 6 ++--- bt-service-adaptation/services/bt-service-dpm.c | 8 +++---- bt-service/bt-request-handler.c | 6 ++--- bt-service/bt-service-adapter.c | 8 +++---- bt-service/bt-service-audio.c | 12 +++++----- bt-service/bt-service-headset-connection.c | 26 +++++++++++----------- 8 files changed, 45 insertions(+), 47 deletions(-) diff --git a/bt-api/bt-adapter.c b/bt-api/bt-adapter.c index 7729084..1b0de98 100644 --- a/bt-api/bt-adapter.c +++ b/bt-api/bt-adapter.c @@ -28,7 +28,7 @@ static int __bt_fill_device_list(GArray *out_param2, GPtrArray **dev_list) { int i; guint size; - bluetooth_device_info_t info; + bluetooth_device_info_t *info; BT_CHECK_PARAMETER(out_param2, return); BT_CHECK_PARAMETER(dev_list, return); @@ -45,10 +45,10 @@ static int __bt_fill_device_list(GArray *out_param2, GPtrArray **dev_list) for (i = 0; i < size; i++) { bluetooth_device_info_t *dev_info = NULL; - info = g_array_index(out_param2, + info = &g_array_index(out_param2, bluetooth_device_info_t, i); - dev_info = g_memdup(&info, sizeof(bluetooth_device_info_t)); + dev_info = g_memdup(info, sizeof(bluetooth_device_info_t)); if (dev_info) g_ptr_array_add(*dev_list, (gpointer)dev_info); diff --git a/bt-api/bt-avrcp.c b/bt-api/bt-avrcp.c index 02a6cf6..d0fa661 100644 --- a/bt-api/bt-avrcp.c +++ b/bt-api/bt-avrcp.c @@ -491,7 +491,7 @@ BT_EXPORT_API int bluetooth_media_control_get_track_info( media_metadata_attributes_t *metadata) { int result; - media_metadata_t meta_data; + media_metadata_t *meta_data; BT_CHECK_PARAMETER(metadata, return); BT_CHECK_ENABLED(return); @@ -509,17 +509,15 @@ BT_EXPORT_API int bluetooth_media_control_get_track_info( result = _bt_send_request(BT_BLUEZ_SERVICE, BT_AVRCP_GET_TRACK_INFO, in_param1, in_param2, in_param3, in_param4, &out_param); - memset(&meta_data, 0x00, sizeof(media_metadata_t)); - - meta_data = g_array_index(out_param, media_metadata_t, 0); + meta_data = &g_array_index(out_param, media_metadata_t, 0); - metadata->title = g_strdup(meta_data.title); - metadata->artist = g_strdup(meta_data.artist); - metadata->album = g_strdup(meta_data.album); - metadata->genre = g_strdup(meta_data.genre); - metadata->total_tracks = meta_data.total_tracks; - metadata->number = meta_data.number; - metadata->duration = (int64_t) meta_data.duration; + metadata->title = g_strdup(meta_data->title); + metadata->artist = g_strdup(meta_data->artist); + metadata->album = g_strdup(meta_data->album); + metadata->genre = g_strdup(meta_data->genre); + metadata->total_tracks = meta_data->total_tracks; + metadata->number = meta_data->number; + metadata->duration = (int64_t) meta_data->duration; BT_FREE_PARAMS(in_param1, in_param2, in_param3, in_param4, out_param); diff --git a/bt-service-adaptation/services/bt-request-handler.c b/bt-service-adaptation/services/bt-request-handler.c index e369320..b6f7e55 100644 --- a/bt-service-adaptation/services/bt-request-handler.c +++ b/bt-service-adaptation/services/bt-request-handler.c @@ -2978,7 +2978,7 @@ int __bt_obexd_request(int function_name, BT_DBG("BT_OPP_PUSH_FILES"); int i; bluetooth_device_address_t address = { {0} }; - bt_file_path_t path; + bt_file_path_t *path; char **file_path; int file_count; GArray *param2; @@ -2994,8 +2994,8 @@ int __bt_obexd_request(int function_name, __bt_fill_garray_from_variant(in_param2, param2); for (i = 0; i < file_count; i++) { - path = g_array_index(param2, bt_file_path_t, i); - file_path[i] = g_strdup(path.path); + path = &g_array_index(param2, bt_file_path_t, i); + file_path[i] = g_strdup(path->path); } BT_DBG("_bt_opp_client_push_files"); result = _bt_opp_client_push_files(request_id, context, diff --git a/bt-service-adaptation/services/bt-service-dpm.c b/bt-service-adaptation/services/bt-service-dpm.c index d8b27d4..c30f28e 100644 --- a/bt-service-adaptation/services/bt-service-dpm.c +++ b/bt-service-adaptation/services/bt-service-dpm.c @@ -293,8 +293,8 @@ int _bt_dpm_add_bluetooth_uuids_to_blacklist(const char *uuid) for (i = 0; i < (addr_list->len / sizeof(bluetooth_device_address_t)); i++) { char address[BT_ADDRESS_STRING_SIZE]; - bluetooth_device_address_t addr = g_array_index(addr_list, bluetooth_device_address_t, i); - _bt_convert_addr_type_to_string(address, addr.addr); + bluetooth_device_address_t *addr = &g_array_index(addr_list, bluetooth_device_address_t, i); + _bt_convert_addr_type_to_string(address, addr->addr); BT_INFO("device[%s] is in blacklist uuid, will be disconnected", address); // TODO: need to implement disconnect logic } @@ -606,8 +606,8 @@ int _bt_dpm_set_bluetooth_profile_state(dpm_profile_t profile, dpm_status_t valu for (i = 0; i < (addr_list->len / sizeof(bluetooth_device_address_t)); i++) { char address[BT_ADDRESS_STRING_SIZE]; - bluetooth_device_address_t addr = g_array_index(addr_list, bluetooth_device_address_t, i); - _bt_convert_addr_type_to_string(address, addr.addr); + bluetooth_device_address_t *addr = &g_array_index(addr_list, bluetooth_device_address_t, i); + _bt_convert_addr_type_to_string(address, addr->addr); BT_INFO("device[%s] is in blacklist uuid, will be disconnected", address); // TODO: need to implement disconnect logic } diff --git a/bt-service/bt-request-handler.c b/bt-service/bt-request-handler.c index e513198..6650376 100644 --- a/bt-service/bt-request-handler.c +++ b/bt-service/bt-request-handler.c @@ -2207,7 +2207,7 @@ int __bt_obexd_request(int function_name, BT_DBG("BT_OPP_PUSH_FILES"); int i; bluetooth_device_address_t address = { {0} }; - bt_file_path_t path; + bt_file_path_t *path; char **file_path; int file_count; GArray *param2; @@ -2223,8 +2223,8 @@ int __bt_obexd_request(int function_name, __bt_fill_garray_from_variant(in_param2, param2); for (i = 0; i < file_count; i++) { - path = g_array_index(param2, bt_file_path_t, i); - file_path[i] = g_strdup(path.path); + path = &g_array_index(param2, bt_file_path_t, i); + file_path[i] = g_strdup(path->path); } BT_DBG("_bt_opp_client_push_files"); result = _bt_opp_client_push_files(request_id, context, diff --git a/bt-service/bt-service-adapter.c b/bt-service/bt-service-adapter.c index eb358f2..078bca7 100644 --- a/bt-service/bt-service-adapter.c +++ b/bt-service/bt-service-adapter.c @@ -1228,7 +1228,7 @@ static gboolean __bt_disconnect_all(void) GVariant *result; GError *error = NULL; GArray *device_list; - bluetooth_device_info_t info; + bluetooth_device_info_t *info; guint size; char *device_path = NULL; char address[BT_ADDRESS_STRING_SIZE] = { 0 }; @@ -1250,12 +1250,12 @@ static gboolean __bt_disconnect_all(void) for (i = 0; i < size; i++) { - info = g_array_index(device_list, + info = &g_array_index(device_list, bluetooth_device_info_t, i); - if (info.connected != BLUETOOTH_CONNECTED_LINK_NONE) { + if (info->connected != BLUETOOTH_CONNECTED_LINK_NONE) { BT_DBG("Found Connected device"); - _bt_convert_addr_type_to_string(address, info.device_address.addr); + _bt_convert_addr_type_to_string(address, info->device_address.addr); device_path = _bt_get_device_object_path(address); if (device_path == NULL) continue; diff --git a/bt-service/bt-service-audio.c b/bt-service/bt-service-audio.c index 8118f4e..ff76b58 100644 --- a/bt-service/bt-service-audio.c +++ b/bt-service/bt-service-audio.c @@ -603,7 +603,7 @@ static gboolean __bt_device_support_uuid(char *remote_address, int size; int i; int j; - bluetooth_device_info_t info; + bluetooth_device_info_t *info; char bond_address[BT_ADDRESS_STRING_SIZE] = { 0 }; gboolean ret = FALSE; @@ -615,23 +615,23 @@ static gboolean __bt_device_support_uuid(char *remote_address, size = (dev_list->len) / sizeof(bluetooth_device_info_t); for (i = 0; i < size; i++) { - info = g_array_index(dev_list, bluetooth_device_info_t, i); + info = &g_array_index(dev_list, bluetooth_device_info_t, i); _bt_convert_addr_type_to_string(bond_address, - info.device_address.addr); + info->device_address.addr); if (strcmp(bond_address, remote_address) != 0) continue; BT_INFO("Device address Matched"); j = 0; - while (j != info.service_index) { + while (j != info->service_index) { if (type == BT_AUDIO_HSP) { - if (strcmp(info.uuids[j], HFP_HS_UUID) == 0) { + if (strcmp(info->uuids[j], HFP_HS_UUID) == 0) { BT_INFO("HFP HS UUID exists"); ret = TRUE; goto end; } } else if (type == BT_AUDIO_A2DP) { - if (strcmp(info.uuids[j], A2DP_SINK_UUID) == 0) { + if (strcmp(info->uuids[j], A2DP_SINK_UUID) == 0) { BT_INFO("A2DP SINK UUID exists"); ret = TRUE; goto end; diff --git a/bt-service/bt-service-headset-connection.c b/bt-service/bt-service-headset-connection.c index f88ffce..e489422 100644 --- a/bt-service/bt-service-headset-connection.c +++ b/bt-service/bt-service-headset-connection.c @@ -128,7 +128,7 @@ void _bt_get_bluetooth_device_info(char *remote_address, bluetooth_device_info_t GArray *dev_list = NULL; int size = 0; int i = 0; - bluetooth_device_info_t info; + bluetooth_device_info_t *info; char bond_address[BT_ADDRESS_STRING_SIZE] = { 0 }; if (device == NULL) @@ -139,11 +139,11 @@ void _bt_get_bluetooth_device_info(char *remote_address, bluetooth_device_info_t _bt_get_bonded_devices(&dev_list); size = (dev_list->len) / sizeof(bluetooth_device_info_t); for (i = 0; i < size; i++) { - info = g_array_index(dev_list, bluetooth_device_info_t, i); - _bt_convert_addr_type_to_string(bond_address, info.device_address.addr); + info = &g_array_index(dev_list, bluetooth_device_info_t, i); + _bt_convert_addr_type_to_string(bond_address, info->device_address.addr); if (strcmp(bond_address, remote_address) == 0) { BT_INFO("Match found"); - memcpy(device, &info, sizeof(bluetooth_device_info_t)); + memcpy(device, info, sizeof(bluetooth_device_info_t)); g_array_free(dev_list, TRUE); return; } @@ -174,33 +174,33 @@ void _bt_start_timer_for_connection(char *remote_address, int connection_type) int size; int i; int j; - bluetooth_device_info_t info; + bluetooth_device_info_t *info; char bond_address[BT_ADDRESS_STRING_SIZE] = { 0 }; dev_list = g_array_new(FALSE, FALSE, sizeof(gchar)); _bt_get_bonded_devices(&dev_list); size = (dev_list->len) / sizeof(bluetooth_device_info_t); for (i = 0; i < size; i++) { - info = g_array_index(dev_list, bluetooth_device_info_t, i); + info = &g_array_index(dev_list, bluetooth_device_info_t, i); j = 0; _bt_convert_addr_type_to_string(bond_address, - info.device_address.addr); + info->device_address.addr); if (strcmp(bond_address, remote_address) != 0) continue; BT_INFO("Device address Matched"); - while (j != info.service_index) { - BT_INFO("UUID %s", info.uuids[j]); + while (j != info->service_index) { + BT_INFO("UUID %s", info->uuids[j]); if (connection_type == BT_AUDIO_A2DP) { - if (strcmp(info.uuids[j], A2DP_SINK_UUID) == 0) { + if (strcmp(info->uuids[j], A2DP_SINK_UUID) == 0) { BT_INFO("Remote Device has A2DP Sink Support start timer"); - _bt_headset_add_timer_function(BT_AUDIO_A2DP, &info); + _bt_headset_add_timer_function(BT_AUDIO_A2DP, info); goto end; } } else { - if (strcmp(info.uuids[j], HFP_HS_UUID) == 0) { + if (strcmp(info->uuids[j], HFP_HS_UUID) == 0) { BT_INFO("Remote Device has HFP Sink Support start timer"); - _bt_headset_add_timer_function(BT_AUDIO_HSP, &info); + _bt_headset_add_timer_function(BT_AUDIO_HSP, info); goto end; } } -- 2.7.4