QWindowsXPStyle: use QVarLengthArray instead new for memory allocation
Avoid the creation of a temporary buffer by using QVarLengthArray instead. Normally GetRegionData() only returns one rect (~48bytes) so it will fit into the QVLA without a memory allocation Change-Id: I279693e17e2f9f2c1c75504c3e5c1de3d45084ec Reviewed-by: Volker Hilsheimer <volker.hilsheimer@qt.io>
This commit is contained in:
parent
9b643bc6c9
commit
b528e44f5a
@ -504,29 +504,29 @@ QRegion QWindowsVistaStylePrivate::region(QWindowsThemeData &themeData)
|
||||
QRegion region;
|
||||
|
||||
if (success) {
|
||||
const auto numBytes = GetRegionData(dest, 0, nullptr);
|
||||
if (numBytes == 0)
|
||||
return QRegion();
|
||||
|
||||
char *buf = new (std::nothrow) char[numBytes];
|
||||
if (!buf)
|
||||
return QRegion();
|
||||
|
||||
RGNDATA *rd = reinterpret_cast<RGNDATA*>(buf);
|
||||
if (GetRegionData(dest, numBytes, rd) == 0) {
|
||||
delete [] buf;
|
||||
return QRegion();
|
||||
QVarLengthArray<char> buf(256);
|
||||
RGNDATA *rd = reinterpret_cast<RGNDATA *>(buf.data());
|
||||
if (GetRegionData(dest, buf.size(), rd) == 0) {
|
||||
const auto numBytes = GetRegionData(dest, 0, nullptr);
|
||||
if (numBytes > 0) {
|
||||
buf.resize(numBytes);
|
||||
rd = reinterpret_cast<RGNDATA *>(buf.data());
|
||||
if (GetRegionData(dest, numBytes, rd) == 0)
|
||||
rd = nullptr;
|
||||
} else {
|
||||
rd = nullptr;
|
||||
}
|
||||
}
|
||||
|
||||
RECT *r = reinterpret_cast<RECT*>(rd->Buffer);
|
||||
for (uint i = 0; i < rd->rdh.nCount; ++i) {
|
||||
QRect rect;
|
||||
rect.setCoords(int(r->left * factor), int(r->top * factor), int((r->right - 1) * factor), int((r->bottom - 1) * factor));
|
||||
++r;
|
||||
region |= rect;
|
||||
if (rd) {
|
||||
RECT *r = reinterpret_cast<RECT *>(rd->Buffer);
|
||||
for (uint i = 0; i < rd->rdh.nCount; ++i) {
|
||||
QRect rect;
|
||||
rect.setCoords(int(r->left * factor), int(r->top * factor),
|
||||
int((r->right - 1) * factor), int((r->bottom - 1) * factor));
|
||||
++r;
|
||||
region |= rect;
|
||||
}
|
||||
}
|
||||
|
||||
delete [] buf;
|
||||
}
|
||||
|
||||
DeleteObject(hRgn);
|
||||
|
Loading…
Reference in New Issue
Block a user