From 0b88b4596e6265863e75e7aabcca52734e147fae Mon Sep 17 00:00:00 2001 From: Clyne Sullivan Date: Fri, 24 Feb 2023 19:09:53 -0500 Subject: compact implementation; runs on msp430 --- corewords.cpp | 30 +++++++++++++++++------------- 1 file changed, 17 insertions(+), 13 deletions(-) (limited to 'corewords.cpp') diff --git a/corewords.cpp b/corewords.cpp index 2d98117..c0cec48 100644 --- a/corewords.cpp +++ b/corewords.cpp @@ -18,6 +18,9 @@ #include "corewords.hpp" +#include +#include + void CoreWords::run(unsigned int index, State& state) { auto getword = [&state] { @@ -197,18 +200,19 @@ void CoreWords::run(unsigned int index, State& state) } } -int CoreWords::findi(std::string_view word) +int CoreWords::findi(const char *word) { + const auto size = std::strlen(word); std::size_t i; int wordsi = 0; - std::string_view words (wordsarr, sizeof(wordsarr)); - - for (i = 0; i < words.size();) { - const auto end = words.find_first_of({"\0\1", 2}, i); + for (i = 0; i < sizeof(wordsarr);) { + auto end = i; + while (wordsarr[end] > '\1') + ++end; - if (word == words.substr(i, end - i)) - return words[end] == '\0' ? wordsi : (wordsi | Compiletime); + if (size == end - i && !std::strncmp(word, wordsarr + i, size)) + return wordsarr[end] == '\0' ? wordsi : (wordsi | Compiletime); ++wordsi; i = end + 1; @@ -222,13 +226,13 @@ int CoreWords::findi(State& state, Word word) std::size_t i; int wordsi = 0; - std::string_view words (wordsarr, sizeof(wordsarr)); - - for (i = 0; i < words.size();) { - const auto end = words.find_first_of({"\0\1", 2}, i); + for (i = 0; i < sizeof(wordsarr);) { + auto end = i; + while (wordsarr[end] > '\1') + ++end; - if (state.dict.equal(word, words.substr(i, end - i))) - return words[end] == '\0' ? wordsi : (wordsi | Compiletime); + if (state.dict.equal(word, wordsarr + i, end - i)) + return wordsarr[end] == '\0' ? wordsi : (wordsi | Compiletime); ++wordsi; i = end + 1; -- cgit v1.2.3