Fixed some low hanging fruit in performance.
This commit is contained in:
@@ -12,56 +12,55 @@ namespace MalachScript::Parser {
|
||||
TextSpan _span;
|
||||
|
||||
public:
|
||||
LexToken(TextSpan span) : _span(span) {}
|
||||
inline LexToken(const TextSpan& span) : _span(span) {}
|
||||
virtual ~LexToken() = default;
|
||||
[[nodiscard]] virtual LexTokenKind GetKind() const noexcept = 0;
|
||||
[[nodiscard]] const std::unique_ptr<const LexToken>& GetNext() const noexcept { return _next; }
|
||||
[[nodiscard]] const TextSpan& GetSpan() const noexcept { return _span; }
|
||||
[[nodiscard]] inline const std::unique_ptr<const LexToken>& GetNext() const noexcept { return _next; }
|
||||
[[nodiscard]] inline const TextSpan& GetSpan() const noexcept { return _span; }
|
||||
|
||||
void SetNext(LexToken* token){
|
||||
_next = std::unique_ptr<const LexToken>(token);
|
||||
}
|
||||
inline void SetNext(LexToken* token) { _next = std::unique_ptr<const LexToken>(token); }
|
||||
};
|
||||
|
||||
template <LexTokenKind kind> class LexTokenImpl : public LexToken {
|
||||
public:
|
||||
LexTokenImpl(TextSpan span) : LexToken(span){};
|
||||
[[nodiscard]] LexTokenKind GetKind() const noexcept final { return kind; }
|
||||
inline LexTokenImpl(const TextSpan& span) : LexToken(span){};
|
||||
[[nodiscard]] inline LexTokenKind GetKind() const noexcept final { return kind; }
|
||||
};
|
||||
|
||||
class IntegerLiteral : public LexTokenImpl<LexTokenKind::IntegerLiteral> {
|
||||
uint64_t _value;
|
||||
|
||||
public:
|
||||
IntegerLiteral(TextSpan span, uint64_t value)
|
||||
IntegerLiteral(const TextSpan& span, uint64_t value)
|
||||
: LexTokenImpl<LexTokenKind::IntegerLiteral>(span), _value(value) {}
|
||||
[[nodiscard]] uint64_t GetValue() const noexcept { return _value; }
|
||||
[[nodiscard]] inline uint64_t GetValue() const noexcept { return _value; }
|
||||
};
|
||||
|
||||
class FloatLiteral : public LexTokenImpl<LexTokenKind::FloatLiteral> {
|
||||
double _value;
|
||||
|
||||
public:
|
||||
FloatLiteral(TextSpan span, double value) : LexTokenImpl<LexTokenKind::FloatLiteral>(span), _value(value) {}
|
||||
[[nodiscard]] double GetValue() const noexcept { return _value; }
|
||||
FloatLiteral(const TextSpan& span, double value)
|
||||
: LexTokenImpl<LexTokenKind::FloatLiteral>(span), _value(value) {}
|
||||
[[nodiscard]] inline double GetValue() const noexcept { return _value; }
|
||||
};
|
||||
|
||||
class StringLiteral : public LexTokenImpl<LexTokenKind::StringLiteral> {
|
||||
std::u8string _value;
|
||||
|
||||
public:
|
||||
StringLiteral(TextSpan span, std::u8string value)
|
||||
StringLiteral(const TextSpan& span, std::u8string value)
|
||||
: LexTokenImpl<LexTokenKind::StringLiteral>(span), _value(std::move(value)) {}
|
||||
[[nodiscard]] const std::u8string& GetValue() const noexcept { return _value; }
|
||||
[[nodiscard]] inline const std::u8string& GetValue() const noexcept { return _value; }
|
||||
};
|
||||
|
||||
class IdentifierToken : public LexTokenImpl<LexTokenKind::Identifier> {
|
||||
Identifier _value;
|
||||
|
||||
public:
|
||||
IdentifierToken(TextSpan span, Identifier value)
|
||||
IdentifierToken(const TextSpan& span, Identifier value)
|
||||
: LexTokenImpl<LexTokenKind::Identifier>(span), _value(value) {}
|
||||
[[nodiscard]] const Identifier& GetValue() const noexcept { return _value; }
|
||||
[[nodiscard]] inline const Identifier& GetValue() const noexcept { return _value; }
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
@@ -466,7 +466,7 @@ namespace MalachScript::Parser {
|
||||
}
|
||||
auto str = _script.substr(start, offset);
|
||||
Progress(offset - 1);
|
||||
auto hash = Identifier::HashStringView(str);
|
||||
auto hash = Identifier::Hash(str);
|
||||
switch (hash) {
|
||||
case Identifier::Hash(u8"and"):
|
||||
return Create<LexTokenImpl<LexTokenKind::AndKeyword>>(TextSpan(start, _position));
|
||||
|
||||
@@ -38,7 +38,7 @@ namespace MalachScript::Parser {
|
||||
if (pos >= _scriptLength) {
|
||||
return '\0';
|
||||
}
|
||||
return *(_script.data() + pos);
|
||||
return _script[pos];
|
||||
}
|
||||
|
||||
LexToken* LexNext();
|
||||
|
||||
Reference in New Issue
Block a user