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.
This commit is contained in:
parent
876090aeea
commit
d3132b114c
@ -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
|
||||
|
Loading…
Reference in New Issue
Block a user