From 8d5829dd269b3d4407ddd1ae9010e86e2c23b1a8 Mon Sep 17 00:00:00 2001 From: Misa Date: Fri, 12 Feb 2021 13:45:32 -0800 Subject: [PATCH] Remove indentation level from checking for empty pText Instead of checking the length() of an std::string, just check if pText[0] is equal to '\0'. This will have to be done anyway, because I'm going to get rid of the std::string allocation here, and I noticed this inefficiency in the indentation, so I'm going to remove it. The actual unindent will be done in the next commit. --- desktop_version/src/Game.cpp | 10 ++-------- desktop_version/src/editor.cpp | 11 ++--------- 2 files changed, 4 insertions(+), 17 deletions(-) diff --git a/desktop_version/src/Game.cpp b/desktop_version/src/Game.cpp index 28250408..fb2ac202 100644 --- a/desktop_version/src/Game.cpp +++ b/desktop_version/src/Game.cpp @@ -443,17 +443,14 @@ void Game::updatecustomlevelstats(std::string clevel, int cscore) } #define LOAD_ARRAY_RENAME(ARRAY_NAME, DEST) \ - if (pKey == #ARRAY_NAME) \ + if (pKey == #ARRAY_NAME && pText[0] != '\0') \ { \ std::string TextString = pText; \ - if (TextString.length()) \ - { \ std::vector values = split(TextString, ','); \ for (int i = 0; i < VVV_min(SDL_arraysize(DEST), values.size()); i++) \ { \ DEST[i] = help.Int(values[i].c_str()); \ } \ - } \ } #define LOAD_ARRAY(ARRAY_NAME) LOAD_ARRAY_RENAME(ARRAY_NAME, ARRAY_NAME) @@ -542,17 +539,14 @@ void Game::loadcustomlevelstats() LOAD_ARRAY_RENAME(customlevelscore, customlevelscores) - if (pKey == "customlevelstats") + if (pKey == "customlevelstats" && pText[0] != '\0') { std::string TextString = (pText); - if(TextString.length()) - { std::vector values = split(TextString,'|'); for(size_t i = 0; i < values.size(); i++) { customlevelnames.push_back(values[i]); } - } } } diff --git a/desktop_version/src/editor.cpp b/desktop_version/src/editor.cpp index 5539b22b..b5f378da 100644 --- a/desktop_version/src/editor.cpp +++ b/desktop_version/src/editor.cpp @@ -1752,11 +1752,9 @@ bool editorclass::load(std::string& _path) } - if (pKey == "contents") + if (pKey == "contents" && pText[0] != '\0') { std::string TextString = (pText); - if(TextString.length()) - { std::vector values = split(TextString,','); SDL_memset(contents, 0, sizeof(contents)); int x =0; @@ -1772,7 +1770,6 @@ bool editorclass::load(std::string& _path) } } - } } @@ -1873,11 +1870,9 @@ bool editorclass::load(std::string& _path) } } - if (pKey == "script") + if (pKey == "script" && pText[0] != '\0') { std::string TextString = (pText); - if(TextString.length()) - { std::vector values = split(TextString,'|'); script.clearcustom(); Script script_; @@ -1910,8 +1905,6 @@ bool editorclass::load(std::string& _path) //Add the script if we have a preceding header script.customscripts.push_back(script_); } - - } } }