diff options
author | Konstantin Ritt <ritt.ks@gmail.com> | 2012-07-01 13:10:10 +0300 |
---|---|---|
committer | Qt by Nokia <qt-info@nokia.com> | 2012-07-03 01:09:14 +0200 |
commit | 48925d98f3970f3b0b8d66839e6c2046e18fa964 (patch) | |
tree | 7f75413d29939624930224b1228df74a6c36b675 /src | |
parent | 865b910dc083c6341587ea1e91656eccef5c3f04 (diff) |
Optimize QWindowsFontEngineDirectWrite::initFontInfo() a bit
by using QVarLengthArray instead of allocating memory on a heap
and by skipping a subsequent checks & calls in some cases.
Change-Id: I300d8eaf02ef718ce50833b7c2ca7ebe8cfd0224
Reviewed-by: Friedemann Kleint <Friedemann.Kleint@nokia.com>
Diffstat (limited to 'src')
-rw-r--r-- | src/plugins/platforms/windows/qwindowsfontenginedirectwrite.cpp | 34 |
1 files changed, 17 insertions, 17 deletions
diff --git a/src/plugins/platforms/windows/qwindowsfontenginedirectwrite.cpp b/src/plugins/platforms/windows/qwindowsfontenginedirectwrite.cpp index 568de480a0..80f91ea5fd 100644 --- a/src/plugins/platforms/windows/qwindowsfontenginedirectwrite.cpp +++ b/src/plugins/platforms/windows/qwindowsfontenginedirectwrite.cpp @@ -47,6 +47,7 @@ #include <QtCore/QSettings> #include <QtCore/QtEndian> +#include <QtCore/QVarLengthArray> #include <dwrite.h> #include <d2d1.h> @@ -680,39 +681,38 @@ void QWindowsFontEngineDirectWrite::initFontInfo(const QFontDef &request, hr = fontFamily->GetFamilyNames(&familyNames); UINT32 index = 0; - BOOL exists = false; - - wchar_t localeName[LOCALE_NAME_MAX_LENGTH]; if (SUCCEEDED(hr)) { - int defaultLocaleSuccess = GetUserDefaultLocaleName(localeName, LOCALE_NAME_MAX_LENGTH); + BOOL exists = false; + wchar_t localeName[LOCALE_NAME_MAX_LENGTH]; + int defaultLocaleSuccess = GetUserDefaultLocaleName(localeName, LOCALE_NAME_MAX_LENGTH); if (defaultLocaleSuccess) hr = familyNames->FindLocaleName(localeName, &index, &exists); if (SUCCEEDED(hr) && !exists) hr = familyNames->FindLocaleName(L"en-us", &index, &exists); + + if (!exists) + index = 0; } - if (!exists) - index = 0; + // Get the family name. + if (SUCCEEDED(hr)) { + UINT32 length = 0; - UINT32 length = 0; - if (SUCCEEDED(hr)) hr = familyNames->GetStringLength(index, &length); - wchar_t *name = new (std::nothrow) wchar_t[length+1]; - if (name == NULL) - hr = E_OUTOFMEMORY; + if (SUCCEEDED(hr)) { + QVarLengthArray<wchar_t, 128> name(length+1); - // Get the family name. - if (SUCCEEDED(hr)) - hr = familyNames->GetString(index, name, length + 1); + hr = familyNames->GetString(index, name.data(), name.size()); - if (SUCCEEDED(hr)) - fontDef.family = QString::fromWCharArray(name); + if (SUCCEEDED(hr)) + fontDef.family = QString::fromWCharArray(name.constData()); + } + } - delete[] name; if (familyNames != NULL) familyNames->Release(); |