From d3132b114c094a2925aa0d0909c8acb67f285ebc Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Sun, 19 Nov 2017 21:37:49 +0100 Subject: [PATCH] Optimize memory allocation in wxArrayString ctors Call assign() instead of Add() in a loop: this is not only shorter, but also ensures that reserve() is called before starting the loop and all the required memory is allocated at once. --- src/common/arrstr.cpp | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/src/common/arrstr.cpp b/src/common/arrstr.cpp index ccc25f23ab..6b3abce10c 100644 --- a/src/common/arrstr.cpp +++ b/src/common/arrstr.cpp @@ -36,8 +36,7 @@ wxArrayString::wxArrayString(size_t sz, const char** a) #if !wxUSE_STD_CONTAINERS Init(false); #endif - for (size_t i=0; i < sz; i++) - Add(a[i]); + assign(a, a + sz); } wxArrayString::wxArrayString(size_t sz, const wchar_t** a) @@ -45,8 +44,7 @@ wxArrayString::wxArrayString(size_t sz, const wchar_t** a) #if !wxUSE_STD_CONTAINERS Init(false); #endif - for (size_t i=0; i < sz; i++) - Add(a[i]); + assign(a, a + sz); } wxArrayString::wxArrayString(size_t sz, const wxString* a) @@ -54,8 +52,7 @@ wxArrayString::wxArrayString(size_t sz, const wxString* a) #if !wxUSE_STD_CONTAINERS Init(false); #endif - for (size_t i=0; i < sz; i++) - Add(a[i]); + assign(a, a + sz); } #if !wxUSE_STD_CONTAINERS