mirror of
https://github.com/mawww/kakoune.git
synced 2024-11-30 23:37:17 +03:00
set Coords/Counts methods as always_inline
They are well tested, and we never want to step into them when debugging
This commit is contained in:
parent
c21368cac5
commit
9240cccf74
13
src/coord.hh
13
src/coord.hh
@ -12,14 +12,17 @@ struct LineAndColumn
|
|||||||
LineType line;
|
LineType line;
|
||||||
ColumnType column;
|
ColumnType column;
|
||||||
|
|
||||||
|
[[gnu::always_inline]]
|
||||||
constexpr LineAndColumn(LineType line = 0, ColumnType column = 0)
|
constexpr LineAndColumn(LineType line = 0, ColumnType column = 0)
|
||||||
: line(line), column(column) {}
|
: line(line), column(column) {}
|
||||||
|
|
||||||
|
[[gnu::always_inline]]
|
||||||
constexpr EffectiveType operator+(EffectiveType other) const
|
constexpr EffectiveType operator+(EffectiveType other) const
|
||||||
{
|
{
|
||||||
return EffectiveType(line + other.line, column + other.column);
|
return EffectiveType(line + other.line, column + other.column);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
[[gnu::always_inline]]
|
||||||
EffectiveType& operator+=(EffectiveType other)
|
EffectiveType& operator+=(EffectiveType other)
|
||||||
{
|
{
|
||||||
line += other.line;
|
line += other.line;
|
||||||
@ -27,11 +30,13 @@ struct LineAndColumn
|
|||||||
return *static_cast<EffectiveType*>(this);
|
return *static_cast<EffectiveType*>(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
[[gnu::always_inline]]
|
||||||
constexpr EffectiveType operator-(EffectiveType other) const
|
constexpr EffectiveType operator-(EffectiveType other) const
|
||||||
{
|
{
|
||||||
return EffectiveType(line - other.line, column - other.column);
|
return EffectiveType(line - other.line, column - other.column);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
[[gnu::always_inline]]
|
||||||
EffectiveType& operator-=(EffectiveType other)
|
EffectiveType& operator-=(EffectiveType other)
|
||||||
{
|
{
|
||||||
line -= other.line;
|
line -= other.line;
|
||||||
@ -39,35 +44,41 @@ struct LineAndColumn
|
|||||||
return *static_cast<EffectiveType*>(this);
|
return *static_cast<EffectiveType*>(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
[[gnu::always_inline]]
|
||||||
constexpr bool operator< (EffectiveType other) const
|
constexpr bool operator< (EffectiveType other) const
|
||||||
{
|
{
|
||||||
return (line != other.line) ? line < other.line
|
return (line != other.line) ? line < other.line
|
||||||
: column < other.column;
|
: column < other.column;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
[[gnu::always_inline]]
|
||||||
constexpr bool operator<= (EffectiveType other) const
|
constexpr bool operator<= (EffectiveType other) const
|
||||||
{
|
{
|
||||||
return (line != other.line) ? line < other.line
|
return (line != other.line) ? line < other.line
|
||||||
: column <= other.column;
|
: column <= other.column;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
[[gnu::always_inline]]
|
||||||
constexpr bool operator> (EffectiveType other) const
|
constexpr bool operator> (EffectiveType other) const
|
||||||
{
|
{
|
||||||
return (line != other.line) ? line > other.line
|
return (line != other.line) ? line > other.line
|
||||||
: column > other.column;
|
: column > other.column;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
[[gnu::always_inline]]
|
||||||
constexpr bool operator>= (EffectiveType other) const
|
constexpr bool operator>= (EffectiveType other) const
|
||||||
{
|
{
|
||||||
return (line != other.line) ? line > other.line
|
return (line != other.line) ? line > other.line
|
||||||
: column >= other.column;
|
: column >= other.column;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
[[gnu::always_inline]]
|
||||||
constexpr bool operator== (EffectiveType other) const
|
constexpr bool operator== (EffectiveType other) const
|
||||||
{
|
{
|
||||||
return line == other.line and column == other.column;
|
return line == other.line and column == other.column;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
[[gnu::always_inline]]
|
||||||
constexpr bool operator!= (EffectiveType other) const
|
constexpr bool operator!= (EffectiveType other) const
|
||||||
{
|
{
|
||||||
return line != other.line or column != other.column;
|
return line != other.line or column != other.column;
|
||||||
@ -76,12 +87,14 @@ struct LineAndColumn
|
|||||||
|
|
||||||
struct ByteCoord : LineAndColumn<ByteCoord, LineCount, ByteCount>
|
struct ByteCoord : LineAndColumn<ByteCoord, LineCount, ByteCount>
|
||||||
{
|
{
|
||||||
|
[[gnu::always_inline]]
|
||||||
constexpr ByteCoord(LineCount line = 0, ByteCount column = 0)
|
constexpr ByteCoord(LineCount line = 0, ByteCount column = 0)
|
||||||
: LineAndColumn(line, column) {}
|
: LineAndColumn(line, column) {}
|
||||||
};
|
};
|
||||||
|
|
||||||
struct CharCoord : LineAndColumn<CharCoord, LineCount, CharCount>
|
struct CharCoord : LineAndColumn<CharCoord, LineCount, CharCount>
|
||||||
{
|
{
|
||||||
|
[[gnu::always_inline]]
|
||||||
constexpr CharCoord(LineCount line = 0, CharCount column = 0)
|
constexpr CharCoord(LineCount line = 0, CharCount column = 0)
|
||||||
: LineAndColumn(line, column) {}
|
: LineAndColumn(line, column) {}
|
||||||
};
|
};
|
||||||
|
31
src/units.hh
31
src/units.hh
@ -10,6 +10,7 @@ template<typename RealType, typename ValueType = int>
|
|||||||
class StronglyTypedNumber
|
class StronglyTypedNumber
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
|
[[gnu::always_inline]]
|
||||||
explicit constexpr StronglyTypedNumber(ValueType value)
|
explicit constexpr StronglyTypedNumber(ValueType value)
|
||||||
: m_value(value)
|
: m_value(value)
|
||||||
{
|
{
|
||||||
@ -17,72 +18,96 @@ public:
|
|||||||
"RealType is not derived from StronglyTypedNumber");
|
"RealType is not derived from StronglyTypedNumber");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
[[gnu::always_inline]]
|
||||||
constexpr RealType operator+(RealType other) const
|
constexpr RealType operator+(RealType other) const
|
||||||
{ return RealType(m_value + other.m_value); }
|
{ return RealType(m_value + other.m_value); }
|
||||||
|
|
||||||
|
[[gnu::always_inline]]
|
||||||
constexpr RealType operator-(RealType other) const
|
constexpr RealType operator-(RealType other) const
|
||||||
{ return RealType(m_value - other.m_value); }
|
{ return RealType(m_value - other.m_value); }
|
||||||
|
|
||||||
|
[[gnu::always_inline]]
|
||||||
constexpr RealType operator*(RealType other) const
|
constexpr RealType operator*(RealType other) const
|
||||||
{ return RealType(m_value * other.m_value); }
|
{ return RealType(m_value * other.m_value); }
|
||||||
|
|
||||||
|
[[gnu::always_inline]]
|
||||||
constexpr RealType operator/(RealType other) const
|
constexpr RealType operator/(RealType other) const
|
||||||
{ return RealType(m_value / other.m_value); }
|
{ return RealType(m_value / other.m_value); }
|
||||||
|
|
||||||
|
[[gnu::always_inline]]
|
||||||
RealType& operator+=(RealType other)
|
RealType& operator+=(RealType other)
|
||||||
{ m_value += other.m_value; return static_cast<RealType&>(*this); }
|
{ m_value += other.m_value; return static_cast<RealType&>(*this); }
|
||||||
|
|
||||||
|
[[gnu::always_inline]]
|
||||||
RealType& operator-=(RealType other)
|
RealType& operator-=(RealType other)
|
||||||
{ m_value -= other.m_value; return static_cast<RealType&>(*this); }
|
{ m_value -= other.m_value; return static_cast<RealType&>(*this); }
|
||||||
|
|
||||||
|
[[gnu::always_inline]]
|
||||||
RealType& operator*=(RealType other)
|
RealType& operator*=(RealType other)
|
||||||
{ m_value *= other.m_value; return static_cast<RealType&>(*this); }
|
{ m_value *= other.m_value; return static_cast<RealType&>(*this); }
|
||||||
|
|
||||||
|
[[gnu::always_inline]]
|
||||||
RealType& operator/=(RealType other)
|
RealType& operator/=(RealType other)
|
||||||
{ m_value /= other.m_value; return static_cast<RealType&>(*this); }
|
{ m_value /= other.m_value; return static_cast<RealType&>(*this); }
|
||||||
|
|
||||||
|
[[gnu::always_inline]]
|
||||||
RealType& operator++()
|
RealType& operator++()
|
||||||
{ ++m_value; return static_cast<RealType&>(*this); }
|
{ ++m_value; return static_cast<RealType&>(*this); }
|
||||||
|
|
||||||
|
[[gnu::always_inline]]
|
||||||
RealType& operator--()
|
RealType& operator--()
|
||||||
{ --m_value; return static_cast<RealType&>(*this); }
|
{ --m_value; return static_cast<RealType&>(*this); }
|
||||||
|
|
||||||
|
[[gnu::always_inline]]
|
||||||
RealType operator++(int)
|
RealType operator++(int)
|
||||||
{ RealType backup(static_cast<RealType&>(*this)); ++m_value; return backup; }
|
{ RealType backup(static_cast<RealType&>(*this)); ++m_value; return backup; }
|
||||||
|
|
||||||
|
[[gnu::always_inline]]
|
||||||
RealType operator--(int)
|
RealType operator--(int)
|
||||||
{ RealType backup(static_cast<RealType&>(*this)); --m_value; return backup; }
|
{ RealType backup(static_cast<RealType&>(*this)); --m_value; return backup; }
|
||||||
|
|
||||||
|
[[gnu::always_inline]]
|
||||||
constexpr RealType operator-() const { return RealType(-m_value); }
|
constexpr RealType operator-() const { return RealType(-m_value); }
|
||||||
|
|
||||||
|
[[gnu::always_inline]]
|
||||||
constexpr RealType operator%(RealType other) const
|
constexpr RealType operator%(RealType other) const
|
||||||
{ return RealType(m_value % other.m_value); }
|
{ return RealType(m_value % other.m_value); }
|
||||||
|
|
||||||
|
[[gnu::always_inline]]
|
||||||
RealType& operator%=(RealType other)
|
RealType& operator%=(RealType other)
|
||||||
{ m_value %= other.m_value; return static_cast<RealType&>(*this); }
|
{ m_value %= other.m_value; return static_cast<RealType&>(*this); }
|
||||||
|
|
||||||
|
[[gnu::always_inline]]
|
||||||
constexpr bool operator==(RealType other) const
|
constexpr bool operator==(RealType other) const
|
||||||
{ return m_value == other.m_value; }
|
{ return m_value == other.m_value; }
|
||||||
|
|
||||||
|
[[gnu::always_inline]]
|
||||||
constexpr bool operator!=(RealType other) const
|
constexpr bool operator!=(RealType other) const
|
||||||
{ return m_value != other.m_value; }
|
{ return m_value != other.m_value; }
|
||||||
|
|
||||||
|
[[gnu::always_inline]]
|
||||||
constexpr bool operator<(RealType other) const
|
constexpr bool operator<(RealType other) const
|
||||||
{ return m_value < other.m_value; }
|
{ return m_value < other.m_value; }
|
||||||
|
|
||||||
|
[[gnu::always_inline]]
|
||||||
constexpr bool operator<=(RealType other) const
|
constexpr bool operator<=(RealType other) const
|
||||||
{ return m_value <= other.m_value; }
|
{ return m_value <= other.m_value; }
|
||||||
|
|
||||||
|
[[gnu::always_inline]]
|
||||||
constexpr bool operator>(RealType other) const
|
constexpr bool operator>(RealType other) const
|
||||||
{ return m_value > other.m_value; }
|
{ return m_value > other.m_value; }
|
||||||
|
|
||||||
|
[[gnu::always_inline]]
|
||||||
constexpr bool operator>=(RealType other) const
|
constexpr bool operator>=(RealType other) const
|
||||||
{ return m_value >= other.m_value; }
|
{ return m_value >= other.m_value; }
|
||||||
|
|
||||||
|
[[gnu::always_inline]]
|
||||||
constexpr bool operator!() const
|
constexpr bool operator!() const
|
||||||
{ return !m_value; }
|
{ return !m_value; }
|
||||||
|
|
||||||
|
[[gnu::always_inline]]
|
||||||
explicit constexpr operator ValueType() const { return m_value; }
|
explicit constexpr operator ValueType() const { return m_value; }
|
||||||
|
[[gnu::always_inline]]
|
||||||
explicit constexpr operator bool() const { return m_value; }
|
explicit constexpr operator bool() const { return m_value; }
|
||||||
private:
|
private:
|
||||||
ValueType m_value;
|
ValueType m_value;
|
||||||
@ -90,9 +115,11 @@ private:
|
|||||||
|
|
||||||
struct LineCount : public StronglyTypedNumber<LineCount, int>
|
struct LineCount : public StronglyTypedNumber<LineCount, int>
|
||||||
{
|
{
|
||||||
|
[[gnu::always_inline]]
|
||||||
constexpr LineCount(int value = 0) : StronglyTypedNumber<LineCount>(value) {}
|
constexpr LineCount(int value = 0) : StronglyTypedNumber<LineCount>(value) {}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
[[gnu::always_inline]]
|
||||||
inline constexpr LineCount operator"" _line(unsigned long long int value)
|
inline constexpr LineCount operator"" _line(unsigned long long int value)
|
||||||
{
|
{
|
||||||
return LineCount(value);
|
return LineCount(value);
|
||||||
@ -100,9 +127,11 @@ inline constexpr LineCount operator"" _line(unsigned long long int value)
|
|||||||
|
|
||||||
struct ByteCount : public StronglyTypedNumber<ByteCount, int>
|
struct ByteCount : public StronglyTypedNumber<ByteCount, int>
|
||||||
{
|
{
|
||||||
|
[[gnu::always_inline]]
|
||||||
constexpr ByteCount(int value = 0) : StronglyTypedNumber<ByteCount>(value) {}
|
constexpr ByteCount(int value = 0) : StronglyTypedNumber<ByteCount>(value) {}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
[[gnu::always_inline]]
|
||||||
inline constexpr ByteCount operator"" _byte(unsigned long long int value)
|
inline constexpr ByteCount operator"" _byte(unsigned long long int value)
|
||||||
{
|
{
|
||||||
return ByteCount(value);
|
return ByteCount(value);
|
||||||
@ -110,9 +139,11 @@ inline constexpr ByteCount operator"" _byte(unsigned long long int value)
|
|||||||
|
|
||||||
struct CharCount : public StronglyTypedNumber<CharCount, int>
|
struct CharCount : public StronglyTypedNumber<CharCount, int>
|
||||||
{
|
{
|
||||||
|
[[gnu::always_inline]]
|
||||||
constexpr CharCount(int value = 0) : StronglyTypedNumber<CharCount>(value) {}
|
constexpr CharCount(int value = 0) : StronglyTypedNumber<CharCount>(value) {}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
[[gnu::always_inline]]
|
||||||
inline constexpr CharCount operator"" _char(unsigned long long int value)
|
inline constexpr CharCount operator"" _char(unsigned long long int value)
|
||||||
{
|
{
|
||||||
return CharCount(value);
|
return CharCount(value);
|
||||||
|
Loading…
Reference in New Issue
Block a user