From 8af3708aa32552c511975b6cf24793d908d56b3a Mon Sep 17 00:00:00 2001 From: PKEuS Date: Thu, 28 Feb 2019 22:34:08 +0100 Subject: [PATCH] Optimization: Library does not need to store "#define " substring for each define --- lib/library.cpp | 6 ++---- lib/preprocessor.cpp | 8 +++----- 2 files changed, 5 insertions(+), 9 deletions(-) diff --git a/lib/library.cpp b/lib/library.cpp index 010d808db..abbe760de 100644 --- a/lib/library.cpp +++ b/lib/library.cpp @@ -224,11 +224,9 @@ Library::Error Library::load(const tinyxml2::XMLDocument &doc) const char *value = node->Attribute("value"); if (value == nullptr) return Error(MISSING_ATTRIBUTE, "value"); - defines.push_back(std::string("#define ") + - name + + defines.push_back(std::string(name) + " " + - value + - "\n"); + value); } else if (nodename == "function") { diff --git a/lib/preprocessor.cpp b/lib/preprocessor.cpp index 8781adc15..b3167b6f7 100644 --- a/lib/preprocessor.cpp +++ b/lib/preprocessor.cpp @@ -529,14 +529,12 @@ static simplecpp::DUI createDUI(const Settings &mSettings, const std::string &cf splitcfg(cfg, dui.defines, emptyString); for (const std::string &def : mSettings.library.defines) { - if (def.compare(0,8,"#define ") != 0) - continue; - std::string s = def.substr(8); - const std::string::size_type pos = s.find_first_of(" ("); + const std::string::size_type pos = def.find_first_of(" ("); if (pos == std::string::npos) { - dui.defines.push_back(s); + dui.defines.push_back(def); continue; } + std::string s = def; if (s[pos] == ' ') { s[pos] = '='; } else {