diff options
author | Neil <nyamatongwe@gmail.com> | 2020-07-14 22:05:01 +1000 |
---|---|---|
committer | Neil <nyamatongwe@gmail.com> | 2020-07-14 22:05:01 +1000 |
commit | f22f08ba07a883c00b07d7d7e7403c83aabf1330 (patch) | |
tree | b200d2f094252961bcae4f5fb54b2b873aca90f1 /include | |
parent | d5c5bce72040af804a00a014cbce453588b7b231 (diff) | |
download | scintilla-mirror-f22f08ba07a883c00b07d7d7e7403c83aabf1330.tar.gz |
Make simple methods on simple classes constexpr.
Diffstat (limited to 'include')
-rw-r--r-- | include/Platform.h | 62 |
1 files changed, 31 insertions, 31 deletions
diff --git a/include/Platform.h b/include/Platform.h index cdaf65140..0164983e9 100644 --- a/include/Platform.h +++ b/include/Platform.h @@ -108,15 +108,15 @@ public: return Point(static_cast<XYPOSITION>(x_), static_cast<XYPOSITION>(y_)); } - bool operator!=(Point other) const noexcept { + constexpr bool operator!=(Point other) const noexcept { return (x != other.x) || (y != other.y); } - Point operator+(Point other) const noexcept { + constexpr Point operator+(Point other) const noexcept { return Point(x + other.x, y + other.y); } - Point operator-(Point other) const noexcept { + constexpr Point operator-(Point other) const noexcept { return Point(x - other.x, y - other.y); } @@ -146,24 +146,24 @@ public: // Other automatically defined methods (assignment, copy constructor, destructor) are fine - bool operator==(const PRectangle &rc) const noexcept { + constexpr bool operator==(const PRectangle &rc) const noexcept { return (rc.left == left) && (rc.right == right) && (rc.top == top) && (rc.bottom == bottom); } - bool Contains(Point pt) const noexcept { + constexpr bool Contains(Point pt) const noexcept { return (pt.x >= left) && (pt.x <= right) && (pt.y >= top) && (pt.y <= bottom); } - bool ContainsWholePixel(Point pt) const noexcept { + constexpr bool ContainsWholePixel(Point pt) const noexcept { // Does the rectangle contain all of the pixel to left/below the point return (pt.x >= left) && ((pt.x+1) <= right) && (pt.y >= top) && ((pt.y+1) <= bottom); } - bool Contains(PRectangle rc) const noexcept { + constexpr bool Contains(PRectangle rc) const noexcept { return (rc.left >= left) && (rc.right <= right) && (rc.top >= top) && (rc.bottom <= bottom); } - bool Intersects(PRectangle other) const noexcept { + constexpr bool Intersects(PRectangle other) const noexcept { return (right > other.left) && (left < other.right) && (bottom > other.top) && (top < other.bottom); } @@ -173,9 +173,9 @@ public: right += xDelta; bottom += yDelta; } - XYPOSITION Width() const noexcept { return right - left; } - XYPOSITION Height() const noexcept { return bottom - top; } - bool Empty() const noexcept { + constexpr XYPOSITION Width() const noexcept { return right - left; } + constexpr XYPOSITION Height() const noexcept { return bottom - top; } + constexpr bool Empty() const noexcept { return (Height() <= 0) || (Width() <= 0); } }; @@ -187,40 +187,40 @@ constexpr const float componentMaximum = 255.0f; class ColourDesired { int co; public: - explicit ColourDesired(int co_=0) noexcept : co(co_) { + constexpr explicit ColourDesired(int co_=0) noexcept : co(co_) { } - ColourDesired(unsigned int red, unsigned int green, unsigned int blue) noexcept : + constexpr ColourDesired(unsigned int red, unsigned int green, unsigned int blue) noexcept : co(red | (green << 8) | (blue << 16)) { } - bool operator==(const ColourDesired &other) const noexcept { + constexpr bool operator==(const ColourDesired &other) const noexcept { return co == other.co; } - int AsInteger() const noexcept { + constexpr int AsInteger() const noexcept { return co; } // Red, green and blue values as bytes 0..255 - unsigned char GetRed() const noexcept { + constexpr unsigned char GetRed() const noexcept { return co & 0xff; } - unsigned char GetGreen() const noexcept { + constexpr unsigned char GetGreen() const noexcept { return (co >> 8) & 0xff; } - unsigned char GetBlue() const noexcept { + constexpr unsigned char GetBlue() const noexcept { return (co >> 16) & 0xff; } // Red, green and blue values as float 0..1.0 - float GetRedComponent() const noexcept { + constexpr float GetRedComponent() const noexcept { return GetRed() / componentMaximum; } - float GetGreenComponent() const noexcept { + constexpr float GetGreenComponent() const noexcept { return GetGreen() / componentMaximum; } - float GetBlueComponent() const noexcept { + constexpr float GetBlueComponent() const noexcept { return GetBlue() / componentMaximum; } }; @@ -230,34 +230,34 @@ public: */ class ColourAlpha : public ColourDesired { public: - explicit ColourAlpha(int co_ = 0) noexcept : ColourDesired(co_) { + constexpr explicit ColourAlpha(int co_ = 0) noexcept : ColourDesired(co_) { } - ColourAlpha(unsigned int red, unsigned int green, unsigned int blue) noexcept : + constexpr ColourAlpha(unsigned int red, unsigned int green, unsigned int blue) noexcept : ColourDesired(red | (green << 8) | (blue << 16)) { } - ColourAlpha(unsigned int red, unsigned int green, unsigned int blue, unsigned int alpha) noexcept : + constexpr ColourAlpha(unsigned int red, unsigned int green, unsigned int blue, unsigned int alpha) noexcept : ColourDesired(red | (green << 8) | (blue << 16) | (alpha << 24)) { } - ColourAlpha(ColourDesired cd, unsigned int alpha) noexcept : + constexpr ColourAlpha(ColourDesired cd, unsigned int alpha) noexcept : ColourDesired(cd.AsInteger() | (alpha << 24)) { } - ColourDesired GetColour() const noexcept { + constexpr ColourDesired GetColour() const noexcept { return ColourDesired(AsInteger() & 0xffffff); } - unsigned char GetAlpha() const noexcept { + constexpr unsigned char GetAlpha() const noexcept { return (AsInteger() >> 24) & 0xff; } - float GetAlphaComponent() const noexcept { + constexpr float GetAlphaComponent() const noexcept { return GetAlpha() / componentMaximum; } - ColourAlpha MixedWith(ColourAlpha other) const noexcept { + constexpr ColourAlpha MixedWith(ColourAlpha other) const noexcept { const unsigned int red = (GetRed() + other.GetRed()) / 2; const unsigned int green = (GetGreen() + other.GetGreen()) / 2; const unsigned int blue = (GetBlue() + other.GetBlue()) / 2; @@ -273,7 +273,7 @@ class ColourStop { public: float position; ColourAlpha colour; - ColourStop(float position_, ColourAlpha colour_) noexcept : + constexpr ColourStop(float position_, ColourAlpha colour_) noexcept : position(position_), colour(colour_) { } }; @@ -291,7 +291,7 @@ struct FontParameters { int technology; int characterSet; - FontParameters( + constexpr FontParameters( const char *faceName_, float size_=10, int weight_=400, |