Skip to content

Commit 64d2833

Browse files
committed
avoid temporary object creations with macro insertions in simplecpp::preprocess()
1 parent 72ecd54 commit 64d2833

File tree

1 file changed

+30
-30
lines changed

1 file changed

+30
-30
lines changed

simplecpp.cpp

Lines changed: 30 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -3303,26 +3303,26 @@ void simplecpp::preprocess(simplecpp::TokenList &output, const simplecpp::TokenL
33033303
#endif
33043304

33053305
std::map<std::string, std::size_t> sizeOfType(rawtokens.sizeOfType);
3306-
sizeOfType.insert(std::make_pair("char", sizeof(char)));
3307-
sizeOfType.insert(std::make_pair("short", sizeof(short)));
3308-
sizeOfType.insert(std::make_pair("short int", sizeOfType["short"]));
3309-
sizeOfType.insert(std::make_pair("int", sizeof(int)));
3310-
sizeOfType.insert(std::make_pair("long", sizeof(long)));
3311-
sizeOfType.insert(std::make_pair("long int", sizeOfType["long"]));
3312-
sizeOfType.insert(std::make_pair("long long", sizeof(long long)));
3313-
sizeOfType.insert(std::make_pair("float", sizeof(float)));
3314-
sizeOfType.insert(std::make_pair("double", sizeof(double)));
3315-
sizeOfType.insert(std::make_pair("long double", sizeof(long double)));
3316-
sizeOfType.insert(std::make_pair("char *", sizeof(char *)));
3317-
sizeOfType.insert(std::make_pair("short *", sizeof(short *)));
3318-
sizeOfType.insert(std::make_pair("short int *", sizeOfType["short *"]));
3319-
sizeOfType.insert(std::make_pair("int *", sizeof(int *)));
3320-
sizeOfType.insert(std::make_pair("long *", sizeof(long *)));
3321-
sizeOfType.insert(std::make_pair("long int *", sizeOfType["long *"]));
3322-
sizeOfType.insert(std::make_pair("long long *", sizeof(long long *)));
3323-
sizeOfType.insert(std::make_pair("float *", sizeof(float *)));
3324-
sizeOfType.insert(std::make_pair("double *", sizeof(double *)));
3325-
sizeOfType.insert(std::make_pair("long double *", sizeof(long double *)));
3306+
sizeOfType.emplace("char", sizeof(char));
3307+
sizeOfType.emplace("short", sizeof(short));
3308+
sizeOfType.emplace("short int", sizeOfType["short"]);
3309+
sizeOfType.emplace("int", sizeof(int));
3310+
sizeOfType.emplace("long", sizeof(long));
3311+
sizeOfType.emplace("long int", sizeOfType["long"]);
3312+
sizeOfType.emplace("long long", sizeof(long long));
3313+
sizeOfType.emplace("float", sizeof(float));
3314+
sizeOfType.emplace("double", sizeof(double));
3315+
sizeOfType.emplace("long double", sizeof(long double));
3316+
sizeOfType.emplace("char *", sizeof(char *));
3317+
sizeOfType.emplace("short *", sizeof(short *));
3318+
sizeOfType.emplace("short int *", sizeOfType["short *"]);
3319+
sizeOfType.emplace("int *", sizeof(int *));
3320+
sizeOfType.emplace("long *", sizeof(long *));
3321+
sizeOfType.emplace("long int *", sizeOfType["long *"]);
3322+
sizeOfType.emplace("long long *", sizeof(long long *));
3323+
sizeOfType.emplace("float *", sizeof(float *));
3324+
sizeOfType.emplace("double *", sizeof(double *));
3325+
sizeOfType.emplace("long double *", sizeof(long double *));
33263326

33273327
// use a dummy vector for the macros because as this is not part of the file and would add an empty entry - e.g. /usr/include/poll.h
33283328
std::vector<std::string> dummy;
@@ -3342,27 +3342,27 @@ void simplecpp::preprocess(simplecpp::TokenList &output, const simplecpp::TokenL
33423342
const std::string lhs(macrostr.substr(0,eq));
33433343
const std::string rhs(eq==std::string::npos ? std::string("1") : macrostr.substr(eq+1));
33443344
const Macro macro(lhs, rhs, dummy);
3345-
macros.insert(std::pair<TokenString,Macro>(macro.name(), macro));
3345+
macros.emplace(macro.name(), macro);
33463346
}
33473347

33483348
const bool strictAnsiUndefined = dui.undefined.find("__STRICT_ANSI__") != dui.undefined.cend();
33493349
if (!isGnu(dui) && !strictAnsiDefined && !strictAnsiUndefined)
3350-
macros.insert(std::pair<TokenString, Macro>("__STRICT_ANSI__", Macro("__STRICT_ANSI__", "1", dummy)));
3350+
macros.emplace("__STRICT_ANSI__", Macro("__STRICT_ANSI__", "1", dummy));
33513351

3352-
macros.insert(std::make_pair("__FILE__", Macro("__FILE__", "__FILE__", dummy)));
3353-
macros.insert(std::make_pair("__LINE__", Macro("__LINE__", "__LINE__", dummy)));
3354-
macros.insert(std::make_pair("__COUNTER__", Macro("__COUNTER__", "__COUNTER__", dummy)));
3352+
macros.emplace("__FILE__", Macro("__FILE__", "__FILE__", dummy));
3353+
macros.emplace("__LINE__", Macro("__LINE__", "__LINE__", dummy));
3354+
macros.emplace("__COUNTER__", Macro("__COUNTER__", "__COUNTER__", dummy));
33553355
struct tm ltime = {};
33563356
getLocaltime(ltime);
3357-
macros.insert(std::make_pair("__DATE__", Macro("__DATE__", getDateDefine(&ltime), dummy)));
3358-
macros.insert(std::make_pair("__TIME__", Macro("__TIME__", getTimeDefine(&ltime), dummy)));
3357+
macros.emplace("__DATE__", Macro("__DATE__", getDateDefine(&ltime), dummy));
3358+
macros.emplace("__TIME__", Macro("__TIME__", getTimeDefine(&ltime), dummy));
33593359

33603360
if (!dui.std.empty()) {
33613361
const cstd_t c_std = simplecpp::getCStd(dui.std);
33623362
if (c_std != CUnknown) {
33633363
const std::string std_def = simplecpp::getCStdString(c_std);
33643364
if (!std_def.empty())
3365-
macros.insert(std::make_pair("__STDC_VERSION__", Macro("__STDC_VERSION__", std_def, dummy)));
3365+
macros.emplace("__STDC_VERSION__", Macro("__STDC_VERSION__", std_def, dummy));
33663366
} else {
33673367
const cppstd_t cpp_std = simplecpp::getCppStd(dui.std);
33683368
if (cpp_std == CPPUnknown) {
@@ -3379,7 +3379,7 @@ void simplecpp::preprocess(simplecpp::TokenList &output, const simplecpp::TokenL
33793379
}
33803380
const std::string std_def = simplecpp::getCppStdString(cpp_std);
33813381
if (!std_def.empty())
3382-
macros.insert(std::make_pair("__cplusplus", Macro("__cplusplus", std_def, dummy)));
3382+
macros.emplace("__cplusplus", Macro("__cplusplus", std_def, dummy));
33833383
}
33843384
}
33853385

@@ -3466,7 +3466,7 @@ void simplecpp::preprocess(simplecpp::TokenList &output, const simplecpp::TokenL
34663466
if (dui.undefined.find(macro.name()) == dui.undefined.end()) {
34673467
const MacroMap::iterator it = macros.find(macro.name());
34683468
if (it == macros.end())
3469-
macros.insert(std::pair<TokenString, Macro>(macro.name(), macro));
3469+
macros.emplace(macro.name(), macro);
34703470
else
34713471
it->second = macro;
34723472
}

0 commit comments

Comments
 (0)