Skip to content

Commit 8e48340

Browse files
authored
Avoid unnecessary copies by using references (#1525)
1 parent 6b5047d commit 8e48340

File tree

5 files changed

+19
-19
lines changed

5 files changed

+19
-19
lines changed

src/sst/core/factory.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -252,7 +252,7 @@ Factory::CreateComponent(ComponentId_t id, const std::string& type, Params& para
252252
bool
253253
Factory::DoesSubComponentSlotExist(const std::string& type, const std::string& slotName)
254254
{
255-
std::string compTypeToLoad = type;
255+
const std::string& compTypeToLoad = type;
256256

257257
std::string elemlib, elem;
258258
std::tie(elemlib, elem) = parseLoadName(compTypeToLoad);

src/sst/core/impl/interactive/simpleDebug.cc

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -400,7 +400,7 @@ SimpleDebugger::cmd_help(std::vector<std::string>& tokens)
400400
}
401401

402402
if ( tokens.size() > 1 ) {
403-
std::string c = tokens[1];
403+
const std::string& c = tokens[1];
404404
if ( cmdHelp.find(c) != cmdHelp.end() ) {
405405
std::cout << c << " " << cmdHelp.at(c) << std::endl;
406406
}
@@ -559,8 +559,8 @@ SimpleDebugger::cmd_print(std::vector<std::string>& tokens)
559559
}
560560

561561
// See if have a -r or not
562-
int recurse = 0;
563-
std::string tok = tokens[1];
562+
int recurse = 0;
563+
const std::string& tok = tokens[1];
564564
if ( tok.size() >= 2 && tok[0] == '-' && tok[1] == 'r' ) {
565565
// Got a -r
566566
std::string num = tok.substr(2);
@@ -744,7 +744,7 @@ SimpleDebugger::cmd_setHandler(std::vector<std::string>& tokens)
744744
size_t tindex = 2;
745745
unsigned handler = 0;
746746
while ( tindex < tokens.size() ) {
747-
std::string type = tokens[tindex++];
747+
const std::string& type = tokens[tindex++];
748748
// printf("%s ", type.c_str());
749749

750750
if ( type == "bc" )
@@ -802,7 +802,7 @@ SimpleDebugger::cmd_addTraceVar(std::vector<std::string>& tokens)
802802
// Get trace vars and add associated objectBuffers
803803
size_t tindex = 2;
804804
while ( tindex < tokens.size() ) {
805-
std::string tvar = tokens[tindex++];
805+
const std::string& tvar = tokens[tindex++];
806806
// printf("%s ", tvar.c_str());
807807

808808
// Find and check trace variable
@@ -1070,12 +1070,12 @@ Core::Serialization::ObjectMapComparison*
10701070
parseComparison(std::vector<std::string>& tokens, size_t& index, Core::Serialization::ObjectMap* obj, std::string& name)
10711071
{
10721072
// Get first comparison
1073-
std::string var = tokens[index++];
1073+
const std::string& var = tokens[index++];
10741074
if ( index >= tokens.size() ) {
10751075
printf("Invalid format for trigger test\n");
10761076
return nullptr;
10771077
}
1078-
std::string opstr = tokens[index++];
1078+
const std::string& opstr = tokens[index++];
10791079
Core::Serialization::ObjectMapComparison::Op op =
10801080
Core::Serialization::ObjectMapComparison::getOperationFromString(opstr);
10811081

@@ -1165,7 +1165,7 @@ parseComparison(std::vector<std::string>& tokens, size_t& index, Core::Serializa
11651165
WatchPoint::WPAction*
11661166
parseAction(std::vector<std::string>& tokens, size_t& index, Core::Serialization::ObjectMap* obj)
11671167
{
1168-
std::string action = tokens[index++];
1168+
const std::string& action = tokens[index++];
11691169

11701170
if ( action == "interactive" ) {
11711171
return new WatchPoint::InteractiveWPAction();
@@ -1188,14 +1188,14 @@ parseAction(std::vector<std::string>& tokens, size_t& index, Core::Serialization
11881188
printf("Missing variable for set command\n");
11891189
return nullptr;
11901190
}
1191-
std::string tvar = tokens[index++];
1191+
const std::string& tvar = tokens[index++];
11921192
// printf("%s ", tvar.c_str());
11931193

11941194
if ( index >= tokens.size() ) {
11951195
printf("Missing value for set command\n");
11961196
return nullptr;
11971197
}
1198-
std::string tval = tokens[index++];
1198+
const std::string& tval = tokens[index++];
11991199

12001200
// Find and check variable
12011201
Core::Serialization::ObjectMap* map = obj->findVariable(tvar);

src/sst/core/model/cfgoutput/xmlConfigOutput.cc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -61,8 +61,8 @@ XMLConfigGraphOutput::generateXML(
6161
// for(auto paramsItr = comp->params.begin(); paramsItr != comp->params.end(); paramsItr++) {
6262
auto keys = comp->params.getKeys();
6363
for ( auto paramsItr = keys.begin(); paramsItr != keys.end(); paramsItr++ ) {
64-
std::string paramName = *paramsItr;
65-
std::string paramValue = comp->params.find<std::string>(*paramsItr);
64+
const std::string& paramName = *paramsItr;
65+
std::string paramValue = comp->params.find<std::string>(*paramsItr);
6666

6767
fprintf(outputFile, "%s%s<param name=\"%s\" value=\"%s\"/>\n", indent.c_str(), " ", paramName.c_str(),
6868
paramValue.c_str());

src/sst/core/model/configGraph.cc

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -437,10 +437,10 @@ ConfigGraph::findComponent(ComponentId_t id) const
437437
ConfigComponent*
438438
ConfigGraph::findComponentByName(const std::string& name)
439439
{
440-
std::string origname(name);
441-
auto index = origname.find(':');
442-
std::string compname = origname.substr(0, index);
443-
auto itr = comps_by_name_.find(compname);
440+
const std::string& origname(name);
441+
auto index = origname.find(':');
442+
std::string compname = origname.substr(0, index);
443+
auto itr = comps_by_name_.find(compname);
444444

445445
// Check to see if component was found
446446
if ( itr == comps_by_name_.end() ) return nullptr;

src/sst/core/simulation.cc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2201,8 +2201,8 @@ Simulation_impl::initialize_interactive_console(const std::string& type)
22012201
{
22022202

22032203
// Need to parse the type string to see if there are any parameters
2204-
std::string actual_type = type;
2205-
SST::Params p {};
2204+
const std::string& actual_type = type;
2205+
SST::Params p {};
22062206
// For now, just ignore parameters
22072207
// size_t index = type.find_first_of('(');
22082208
// if ( index != std::string::npos ) {

0 commit comments

Comments
 (0)