From 32f081c27afbcc7eb91c89abf123360e2b759a22 Mon Sep 17 00:00:00 2001 From: Unknown Date: Sun, 17 Feb 2019 11:07:48 +0100 Subject: [PATCH] Remove unnecessary calls to strlower in drawalpha option --- Minetestmapper/Mapper.cpp | 21 +++++++++++---------- Minetestmapper/util.h | 8 ++------ 2 files changed, 13 insertions(+), 16 deletions(-) diff --git a/Minetestmapper/Mapper.cpp b/Minetestmapper/Mapper.cpp index a645dbd..42db4fb 100644 --- a/Minetestmapper/Mapper.cpp +++ b/Minetestmapper/Mapper.cpp @@ -430,27 +430,27 @@ int Mapper::start(int argc, char *argv[]) { generator.verboseReadColors++; } break; - case 'e': - // Todo: Unnecessary calls to strlower. Optimize + case 'e': { generator.setDrawAlpha(true); - if (!ps.optarg || !*ps.optarg) + const string optarg = strlower(ps.optarg); + if (optarg.empty()) PixelAttribute::setMixMode(PixelAttribute::AlphaMixAverage); - else if (string(ps.optarg) == "cumulative" || strlower(ps.optarg) == "nodarken") + else if (optarg == "cumulative" || optarg == "nodarken") // "nodarken" is supported for backwards compatibility PixelAttribute::setMixMode(PixelAttribute::AlphaMixCumulative); - else if (string(ps.optarg) == "darken" || strlower(ps.optarg) == "cumulative-darken") + else if (optarg == "darken" || optarg == "cumulative-darken") // "darken" is supported for backwards compatibility PixelAttribute::setMixMode(PixelAttribute::AlphaMixCumulativeDarken); - else if (strlower(ps.optarg) == "average") + else if (optarg == "average") PixelAttribute::setMixMode(PixelAttribute::AlphaMixAverage); - else if (strlower(ps.optarg) == "none") + else if (optarg == "none") generator.setDrawAlpha(false); else { - std::cerr << "Invalid parameter to '" << long_options[option_index].name << "': '" << ps.optarg << "'" << std::endl; + cerr << "Invalid parameter to '" << long_options[option_index].name << "': '" << ps.optarg << "'" << endl; usage(); return EXIT_FAILURE; } - break; + } break; case OPT_DRAWAIR: generator.setDrawAir(true); break; @@ -1112,7 +1112,8 @@ bool Mapper::parseNodeCoordinate(istream & is, int & coord, bool & isBlockCoord, } if (is.fail()) return false; - coord = i; + coord = i; // TODO: Find out what i is doing an what it schould do. + //i is uninitialized if c == 42 && wildcard == false && is->fail == false isBlockCoord = false; if (validStreamAtEof(is)) return true; diff --git a/Minetestmapper/util.h b/Minetestmapper/util.h index 164a2cc..b7f84ce 100644 --- a/Minetestmapper/util.h +++ b/Minetestmapper/util.h @@ -1,8 +1,6 @@ +#pragma once -#ifndef _UTIL_H_ -#define _UTIL_H_ - -#include +#include inline std::string strlower(const std::string &s) { @@ -12,5 +10,3 @@ inline std::string strlower(const std::string &s) sl[i] = tolower(sl[i]); return sl; } - -#endif // _UTIL_H_