aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authormitchell <unknown>2019-03-09 16:12:45 -0500
committermitchell <unknown>2019-03-09 16:12:45 -0500
commit87f97c98ec453cca3121a626b02ff8fca82ebc55 (patch)
tree7f90eb8739635b495e30d3665b9443cedb3d28af
parent691ddb784229360488d8aadf4e5b9fc2f5d1f680 (diff)
downloadscintilla-mirror-87f97c98ec453cca3121a626b02ff8fca82ebc55.tar.gz
Backport: Use noexcept and constexpr where possible and reasonable.
Backport of changeset 7280:9cf6a15d6c85, but removed constexpr since it is not supported in C++11.
-rw-r--r--win32/PlatWin.cxx68
-rw-r--r--win32/PlatWin.h6
2 files changed, 36 insertions, 38 deletions
diff --git a/win32/PlatWin.cxx b/win32/PlatWin.cxx
index 3ee758627..1c937a194 100644
--- a/win32/PlatWin.cxx
+++ b/win32/PlatWin.cxx
@@ -62,12 +62,6 @@ namespace Scintilla {
UINT CodePageFromCharSet(DWORD characterSet, UINT documentCodePage);
-RECT RectFromPRectangle(PRectangle prc) noexcept {
- RECT rc = {static_cast<LONG>(prc.left), static_cast<LONG>(prc.top),
- static_cast<LONG>(prc.right), static_cast<LONG>(prc.bottom)};
- return rc;
-}
-
#if defined(USE_D2D)
IDWriteFactory *pIDWriteFactory = nullptr;
ID2D1Factory *pD2DFactory = nullptr;
@@ -152,7 +146,7 @@ struct FormatAndMetrics {
FLOAT yAscent;
FLOAT yDescent;
FLOAT yInternalLeading;
- FormatAndMetrics(HFONT hfont_, int extraFontFlag_, int characterSet_) :
+ FormatAndMetrics(HFONT hfont_, int extraFontFlag_, int characterSet_) noexcept :
technology(SCWIN_TECH_GDI), hfont(hfont_),
#if defined(USE_D2D)
pTextFormat(nullptr),
@@ -165,7 +159,7 @@ struct FormatAndMetrics {
int characterSet_,
FLOAT yAscent_,
FLOAT yDescent_,
- FLOAT yInternalLeading_) :
+ FLOAT yInternalLeading_) noexcept :
technology(SCWIN_TECH_DIRECTWRITE),
hfont{},
pTextFormat(pTextFormat_),
@@ -228,11 +222,11 @@ HFONT FormatAndMetrics::HFont() {
namespace {
-void *PointerFromWindow(HWND hWnd) {
+void *PointerFromWindow(HWND hWnd) noexcept {
return reinterpret_cast<void *>(::GetWindowLongPtr(hWnd, 0));
}
-void SetWindowPointer(HWND hWnd, void *ptr) {
+void SetWindowPointer(HWND hWnd, void *ptr) noexcept {
::SetWindowLongPtr(hWnd, 0, reinterpret_cast<LONG_PTR>(ptr));
}
@@ -241,11 +235,11 @@ HINSTANCE hinstPlatformRes {};
HCURSOR reverseArrowCursor {};
-FormatAndMetrics *FamFromFontID(void *fid) {
+FormatAndMetrics *FamFromFontID(void *fid) noexcept {
return static_cast<FormatAndMetrics *>(fid);
}
-BYTE Win32MapFontQuality(int extraFontFlag) {
+BYTE Win32MapFontQuality(int extraFontFlag) noexcept {
switch (extraFontFlag & SC_EFF_QUALITY_MASK) {
case SC_EFF_QUALITY_NON_ANTIALIASED:
@@ -263,7 +257,7 @@ BYTE Win32MapFontQuality(int extraFontFlag) {
}
#if defined(USE_D2D)
-D2D1_TEXT_ANTIALIAS_MODE DWriteMapFontQuality(int extraFontFlag) {
+D2D1_TEXT_ANTIALIAS_MODE DWriteMapFontQuality(int extraFontFlag) noexcept {
switch (extraFontFlag & SC_EFF_QUALITY_MASK) {
case SC_EFF_QUALITY_NON_ANTIALIASED:
@@ -430,17 +424,17 @@ class SurfaceGDI : public Surface {
void BrushColor(ColourDesired back);
void SetFont(Font &font_);
- void Clear();
+ void Clear() noexcept;
public:
- SurfaceGDI();
+ SurfaceGDI() noexcept;
// Deleted so SurfaceGDI objects can not be copied.
SurfaceGDI(const SurfaceGDI &) = delete;
SurfaceGDI(SurfaceGDI &&) = delete;
SurfaceGDI &operator=(const SurfaceGDI &) = delete;
SurfaceGDI &operator=(SurfaceGDI &&) = delete;
- ~SurfaceGDI() override;
+ ~SurfaceGDI() noexcept override;
void Init(WindowID wid) override;
void Init(SurfaceID sid, WindowID wid) override;
@@ -484,14 +478,14 @@ public:
void SetDBCSMode(int codePage_) override;
};
-SurfaceGDI::SurfaceGDI() {
+SurfaceGDI::SurfaceGDI() noexcept {
}
-SurfaceGDI::~SurfaceGDI() {
+SurfaceGDI::~SurfaceGDI() noexcept {
Clear();
}
-void SurfaceGDI::Clear() {
+void SurfaceGDI::Clear() noexcept {
if (penOld) {
::SelectObject(hdc, penOld);
::DeleteObject(pen);
@@ -658,7 +652,7 @@ void SurfaceGDI::RoundedRectangle(PRectangle rc, ColourDesired fore, ColourDesir
namespace {
// Plot a point into a DWORD buffer symmetrically to all 4 quadrants
-void AllFour(DWORD *pixels, int width, int height, int x, int y, DWORD val) {
+void AllFour(DWORD *pixels, int width, int height, int x, int y, DWORD val) noexcept {
pixels[y*width+x] = val;
pixels[y*width+width-1-x] = val;
pixels[(height-1-y)*width+x] = val;
@@ -677,7 +671,7 @@ DWORD dwordFromBGRA(byte b, byte g, byte r, byte a) noexcept {
return converter.val;
}
-DWORD dwordMultiplied(ColourDesired colour, unsigned int alpha) {
+DWORD dwordMultiplied(ColourDesired colour, unsigned int alpha) noexcept {
return dwordFromBGRA(
static_cast<byte>(colour.GetBlue() * alpha / 255),
static_cast<byte>(colour.GetGreen() * alpha / 255),
@@ -983,11 +977,11 @@ class SurfaceD2D : public Surface {
float dpiScaleX;
float dpiScaleY;
- void Clear();
+ void Clear() noexcept;
void SetFont(Font &font_);
public:
- SurfaceD2D();
+ SurfaceD2D() noexcept;
// Deleted so SurfaceD2D objects can not be copied.
SurfaceD2D(const SurfaceD2D &) = delete;
SurfaceD2D(SurfaceD2D &&) = delete;
@@ -1042,7 +1036,7 @@ public:
void SetDBCSMode(int codePage_) override;
};
-SurfaceD2D::SurfaceD2D() :
+SurfaceD2D::SurfaceD2D() noexcept :
unicodeMode(false),
x(0), y(0) {
@@ -1070,7 +1064,7 @@ SurfaceD2D::~SurfaceD2D() {
Clear();
}
-void SurfaceD2D::Clear() {
+void SurfaceD2D::Clear() noexcept {
if (pBrush) {
pBrush->Release();
pBrush = nullptr;
@@ -1202,7 +1196,7 @@ void SurfaceD2D::MoveTo(int x_, int y_) {
y = y_;
}
-static int Delta(int difference) {
+static int Delta(int difference) noexcept {
if (difference < 0)
return -1;
else if (difference > 0)
@@ -1708,7 +1702,7 @@ Surface *Surface::Allocate(int technology) {
namespace {
-HWND HwndFromWindowID(WindowID wid) {
+HWND HwndFromWindowID(WindowID wid) noexcept {
return static_cast<HWND>(wid);
}
@@ -1737,7 +1731,7 @@ void Window::SetPosition(PRectangle rc) {
namespace {
-static RECT RectFromMonitor(HMONITOR hMonitor) {
+static RECT RectFromMonitor(HMONITOR hMonitor) noexcept {
MONITORINFO mi = {};
mi.cbSize = sizeof(mi);
if (GetMonitorInfo(hMonitor, &mi)) {
@@ -1816,7 +1810,7 @@ void Window::SetFont(Font &font) {
namespace {
-void FlipBitmap(HBITMAP bitmap, int width, int height) {
+void FlipBitmap(HBITMAP bitmap, int width, int height) noexcept {
HDC hdc = ::CreateCompatibleDC(NULL);
if (hdc) {
HBITMAP prevBmp = SelectBitmap(hdc, bitmap);
@@ -1826,7 +1820,7 @@ void FlipBitmap(HBITMAP bitmap, int width, int height) {
}
}
-HCURSOR GetReverseArrowCursor() {
+HCURSOR GetReverseArrowCursor() noexcept {
if (reverseArrowCursor)
return reverseArrowCursor;
@@ -1921,7 +1915,7 @@ class LineToItem {
std::vector<ListItemData> data;
public:
- void Clear() {
+ void Clear() noexcept {
words.clear();
data.clear();
}
@@ -1934,7 +1928,7 @@ public:
return missing;
}
}
- int Count() const {
+ int Count() const noexcept {
return static_cast<int>(data.size());
}
@@ -2784,7 +2778,7 @@ LRESULT PASCAL ListBoxX::StaticWndProc(
namespace {
-bool ListBoxX_Register() {
+bool ListBoxX_Register() noexcept {
WNDCLASSEX wndclassc;
wndclassc.cbSize = sizeof(wndclassc);
// We need CS_HREDRAW and CS_VREDRAW because of the ellipsis that might be drawn for
@@ -2805,7 +2799,7 @@ bool ListBoxX_Register() {
return ::RegisterClassEx(&wndclassc) != 0;
}
-bool ListBoxX_Unregister() {
+bool ListBoxX_Unregister() noexcept {
return ::UnregisterClass(ListBoxX_ClassName, hinstPlatformRes) != 0;
}
@@ -2836,7 +2830,7 @@ class DynamicLibraryImpl : public DynamicLibrary {
protected:
HMODULE h;
public:
- explicit DynamicLibraryImpl(const char *modulePath) {
+ explicit DynamicLibraryImpl(const char *modulePath) noexcept {
h = ::LoadLibraryA(modulePath);
}
@@ -2846,7 +2840,7 @@ public:
}
// Use GetProcAddress to get a pointer to the relevant function.
- Function FindFunction(const char *name) override {
+ Function FindFunction(const char *name) noexcept override {
if (h) {
// C++ standard doesn't like casts between function pointers and void pointers so use a union
union {
@@ -2860,7 +2854,7 @@ public:
}
}
- bool IsValid() override {
+ bool IsValid() noexcept override {
return h != NULL;
}
};
diff --git a/win32/PlatWin.h b/win32/PlatWin.h
index cf357f72d..2a1bcb649 100644
--- a/win32/PlatWin.h
+++ b/win32/PlatWin.h
@@ -13,7 +13,11 @@ namespace Scintilla {
extern void Platform_Initialise(void *hInstance);
extern void Platform_Finalise(bool fromDllMain);
-RECT RectFromPRectangle(PRectangle prc) noexcept;
+RECT RectFromPRectangle(PRectangle prc) noexcept {
+ RECT rc = { static_cast<LONG>(prc.left), static_cast<LONG>(prc.top),
+ static_cast<LONG>(prc.right), static_cast<LONG>(prc.bottom) };
+ return rc;
+}
#if defined(USE_D2D)
extern bool LoadD2D();