From f24a40906aaa7cf4e64fd2c3a0b7fc0b926a910b Mon Sep 17 00:00:00 2001 From: Yuguo Zou Date: Mon, 7 Aug 2017 11:23:30 +0800 Subject: [PATCH 1/2] Use placement new to optimize wifi scan --- targets/TARGET_Realtek/TARGET_AMEBA/RTWInterface.cpp | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/targets/TARGET_Realtek/TARGET_AMEBA/RTWInterface.cpp b/targets/TARGET_Realtek/TARGET_AMEBA/RTWInterface.cpp index c3bd7389770..38b45a82342 100644 --- a/targets/TARGET_Realtek/TARGET_AMEBA/RTWInterface.cpp +++ b/targets/TARGET_Realtek/TARGET_AMEBA/RTWInterface.cpp @@ -73,9 +73,7 @@ static rtw_result_t scan_result_handler( rtw_scan_handler_result_t* malloced_sca } ap.rssi = record->signal_strength; ap.channel = record->channel; - WiFiAccessPoint *accesspoint = new WiFiAccessPoint(ap); - memcpy(&scan_handler->ap_details[scan_handler->ap_num], accesspoint, sizeof(WiFiAccessPoint)); - delete[] accesspoint; + new (&scan_handler->ap_details[scan_handler->ap_num]) WiFiAccessPoint(ap); } scan_handler->ap_num++; } else{ From 215a7906d3840c2c195e08760ea8efd67a89a81e Mon Sep 17 00:00:00 2001 From: Yuguo Zou Date: Thu, 10 Aug 2017 17:36:05 +0800 Subject: [PATCH 2/2] Change to use copy assignment operator for RTWInterface::scan --- targets/TARGET_Realtek/TARGET_AMEBA/RTWInterface.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/targets/TARGET_Realtek/TARGET_AMEBA/RTWInterface.cpp b/targets/TARGET_Realtek/TARGET_AMEBA/RTWInterface.cpp index 38b45a82342..273e3d1a695 100644 --- a/targets/TARGET_Realtek/TARGET_AMEBA/RTWInterface.cpp +++ b/targets/TARGET_Realtek/TARGET_AMEBA/RTWInterface.cpp @@ -73,7 +73,7 @@ static rtw_result_t scan_result_handler( rtw_scan_handler_result_t* malloced_sca } ap.rssi = record->signal_strength; ap.channel = record->channel; - new (&scan_handler->ap_details[scan_handler->ap_num]) WiFiAccessPoint(ap); + scan_handler->ap_details[scan_handler->ap_num] = WiFiAccessPoint(ap); } scan_handler->ap_num++; } else{