From 5f402e71dd0fc52ce0dfd06fd95c07e2341a7bcf Mon Sep 17 00:00:00 2001 From: Jason Turner Date: Thu, 1 Dec 2016 14:47:23 -0700 Subject: [PATCH] Move away from macro, get slight perf boost with hand rolled compare --- .../chaiscript/language/chaiscript_parser.hpp | 25 +++++++++++-------- 1 file changed, 14 insertions(+), 11 deletions(-) diff --git a/include/chaiscript/language/chaiscript_parser.hpp b/include/chaiscript/language/chaiscript_parser.hpp index e693804..5507360 100644 --- a/include/chaiscript/language/chaiscript_parser.hpp +++ b/include/chaiscript/language/chaiscript_parser.hpp @@ -438,15 +438,20 @@ namespace chaiscript } - /// Reads a symbol group from input if it matches the parameter, without skipping initial whitespace - #define Symbol_(t_s, len) \ - ( \ - m_position.remaining() >= len \ - ? std::memcmp(t_s, &(*m_position), len) == 0 \ - ? ((m_position += len),true) \ - :false \ - :false \ - ) + /// Reads a symbol group from input if it matches the parameter, without skipping initial whitespace + inline bool Symbol_(const char *t_s, const size_t len) + { + if (m_position.remaining() >= len) { + const char *file_pos = &(*m_position); + for (size_t pos = 0; pos < len; ++pos) + { + if (t_s[pos] != file_pos[pos]) { return false; } + } + m_position += len; + return true; + } + return false; + } /// Skips any multi-line or single-line comment bool SkipComment() { @@ -2540,8 +2545,6 @@ namespace chaiscript } } -#undef Symbol_ - #if defined(CHAISCRIPT_MSVC) && defined(CHAISCRIPT_PUSHED_MIN_MAX) #undef CHAISCRIPT_PUSHED_MIN_MAX #pragma pop_macro("min")