Skip to content

Commit c95b153

Browse files
committed
Refactorizations:
- Removed some redundant operator=, copy-ctor and dtor implementations - use operator[] instead of at() in library loading code
1 parent f572f3d commit c95b153

4 files changed

Lines changed: 9 additions & 76 deletions

File tree

lib/checkbufferoverrun.cpp

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1978,11 +1978,6 @@ CheckBufferOverrun::ArrayInfo::ArrayInfo()
19781978
{
19791979
}
19801980

1981-
CheckBufferOverrun::ArrayInfo::ArrayInfo(const CheckBufferOverrun::ArrayInfo &ai)
1982-
{
1983-
*this = ai;
1984-
}
1985-
19861981
CheckBufferOverrun::ArrayInfo::ArrayInfo(const Variable *var, const Tokenizer *tokenizer, const unsigned int forcedeclid)
19871982
: _varname(var->name()), _declarationId((forcedeclid == 0U) ? var->declarationId() : forcedeclid)
19881983
{
@@ -1996,17 +1991,6 @@ CheckBufferOverrun::ArrayInfo::ArrayInfo(const Variable *var, const Tokenizer *t
19961991
_element_size = tokenizer->sizeOfType(var->typeEndToken());
19971992
}
19981993

1999-
CheckBufferOverrun::ArrayInfo & CheckBufferOverrun::ArrayInfo::operator=(const CheckBufferOverrun::ArrayInfo &ai)
2000-
{
2001-
if (&ai != this) {
2002-
_element_size = ai._element_size;
2003-
_num = ai._num;
2004-
_declarationId = ai._declarationId;
2005-
_varname = ai._varname;
2006-
}
2007-
return *this;
2008-
}
2009-
20101994
/**
20111995
* Create array info with specified data
20121996
* The intention is that this is only a temporary solution.. all

lib/checkbufferoverrun.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -130,9 +130,7 @@ class CPPCHECKLIB CheckBufferOverrun : public Check {
130130

131131
public:
132132
ArrayInfo();
133-
ArrayInfo(const ArrayInfo &);
134133
ArrayInfo(const Variable *var, const Tokenizer *tokenizer, const unsigned int forcedeclid = 0);
135-
ArrayInfo & operator=(const ArrayInfo &ai);
136134

137135
/**
138136
* Create array info with specified data

lib/library.cpp

Lines changed: 9 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -27,27 +27,6 @@ Library::Library() : allocid(0)
2727
{
2828
}
2929

30-
Library::Library(const Library &lib) :
31-
use(lib.use),
32-
leakignore(lib.leakignore),
33-
argumentChecks(lib.argumentChecks),
34-
returnuninitdata(lib.returnuninitdata),
35-
allocid(lib.allocid),
36-
_alloc(lib._alloc),
37-
_dealloc(lib._dealloc),
38-
_noreturn(lib._noreturn),
39-
_ignorefunction(lib._ignorefunction),
40-
_reporterrors(lib._reporterrors),
41-
_fileextensions(lib._fileextensions),
42-
_keywords(lib._keywords),
43-
_executableblocks(lib._executableblocks),
44-
_importers(lib._importers),
45-
_reflection(lib._reflection)
46-
{
47-
}
48-
49-
Library::~Library() { }
50-
5130
bool Library::load(const char exename[], const char path[])
5231
{
5332
tinyxml2::XMLDocument doc;
@@ -77,9 +56,7 @@ bool Library::load(const char exename[], const char path[])
7756

7857
if (fp==NULL) {
7958
// Try to locate the library configuration in the installation folder..
80-
std::string temp = exename;
81-
std::replace(temp.begin(), temp.end(), '\\', '/');
82-
const std::string installfolder = Path::getPathFromFilename(temp);
59+
const std::string installfolder = Path::fromNativeSeparators(Path::getPathFromFilename(exename));
8360
const std::string filename = installfolder + "cfg/" + fullfilename;
8461
fp = fopen(filename.c_str(), "rb");
8562
}
@@ -169,13 +146,9 @@ bool Library::load(const char exename[], const char path[])
169146
for (const tinyxml2::XMLElement *functionnode = node->FirstChildElement(); functionnode; functionnode = functionnode->NextSiblingElement()) {
170147
if (strcmp(functionnode->Name(), "library") == 0) {
171148
const char * const extension = functionnode->Attribute("extension");
172-
if (_keywords.find(extension) == _keywords.end()) {
173-
std::list<std::string> list;
174-
_keywords[extension] = list;
175-
}
176149
for (const tinyxml2::XMLElement *librarynode = functionnode->FirstChildElement(); librarynode; librarynode = librarynode->NextSiblingElement()) {
177150
if (strcmp(librarynode->Name(), "keyword") == 0) {
178-
_keywords.at(extension).push_back(librarynode->Attribute("name"));
151+
_keywords[extension].push_back(librarynode->Attribute("name"));
179152
} else
180153
return false;
181154
}
@@ -188,15 +161,7 @@ bool Library::load(const char exename[], const char path[])
188161
for (const tinyxml2::XMLElement *functionnode = node->FirstChildElement(); functionnode; functionnode = functionnode->NextSiblingElement()) {
189162
if (strcmp(functionnode->Name(), "exporter") == 0) {
190163
const char * prefix = (functionnode->Attribute("prefix"));
191-
if (prefix) {
192-
std::map<std::string, ExportedFunctions>::const_iterator
193-
it = _exporters.find(prefix);
194-
if (it == _exporters.end()) {
195-
// add the missing list for later on
196-
ExportedFunctions exporter;
197-
_exporters[prefix] = exporter;
198-
}
199-
} else
164+
if (!prefix)
200165
return false;
201166

202167
for (const tinyxml2::XMLElement *enode = functionnode->FirstChildElement(); enode; enode = enode->NextSiblingElement()) {
@@ -216,13 +181,9 @@ bool Library::load(const char exename[], const char path[])
216181
for (const tinyxml2::XMLElement *functionnode = node->FirstChildElement(); functionnode; functionnode = functionnode->NextSiblingElement()) {
217182
if (strcmp(functionnode->Name(), "library") == 0) {
218183
const char * const extension = functionnode->Attribute("extension");
219-
if (_importers.find(extension) == _importers.end()) {
220-
std::list<std::string> list;
221-
_importers[extension] = list;
222-
}
223184
for (const tinyxml2::XMLElement *librarynode = functionnode->FirstChildElement(); librarynode; librarynode = librarynode->NextSiblingElement()) {
224185
if (strcmp(librarynode->Name(), "importer") == 0) {
225-
_importers.at(extension).push_back(librarynode->Attribute("name"));
186+
_importers[extension].push_back(librarynode->Attribute("name"));
226187
} else
227188
return false;
228189
}
@@ -234,15 +195,11 @@ bool Library::load(const char exename[], const char path[])
234195
for (const tinyxml2::XMLElement *functionnode = node->FirstChildElement(); functionnode; functionnode = functionnode->NextSiblingElement()) {
235196
if (strcmp(functionnode->Name(), "library") == 0) {
236197
const char * const extension = functionnode->Attribute("extension");
237-
if (_reflection.find(extension) == _reflection.end()) {
238-
std::map<std::string,int> map;
239-
_reflection[extension] = map;
240-
}
241198
for (const tinyxml2::XMLElement *librarynode = functionnode->FirstChildElement(); librarynode; librarynode = librarynode->NextSiblingElement()) {
242199
if (strcmp(librarynode->Name(), "call") == 0) {
243200
const char * const argString = librarynode->Attribute("arg");
244201
if (argString) {
245-
_reflection.at(extension)[librarynode->Attribute("name")]
202+
_reflection[extension][librarynode->Attribute("name")]
246203
= atoi(argString);
247204
}
248205
} else
@@ -257,23 +214,19 @@ bool Library::load(const char exename[], const char path[])
257214
for (const tinyxml2::XMLElement *functionnode = node->FirstChildElement(); functionnode; functionnode = functionnode->NextSiblingElement()) {
258215
if (strcmp(functionnode->Name(), "library") == 0) {
259216
const char * const extension = functionnode->Attribute("extension");
260-
if (_executableblocks.find(extension) == _executableblocks.end()) {
261-
CodeBlock blockInfo;
262-
_executableblocks[extension] = blockInfo;
263-
}
264217
for (const tinyxml2::XMLElement *librarynode = functionnode->FirstChildElement(); librarynode; librarynode = librarynode->NextSiblingElement()) {
265218
if (strcmp(librarynode->Name(), "block") == 0) {
266-
_executableblocks.at(extension).addBlock(librarynode->Attribute("name"));
219+
_executableblocks[extension].addBlock(librarynode->Attribute("name"));
267220
} else if (strcmp(librarynode->Name(), "structure") == 0) {
268221
const char * start = librarynode->Attribute("start");
269222
if (start)
270-
_executableblocks.at(extension).setStart(start);
223+
_executableblocks[extension].setStart(start);
271224
const char * end = librarynode->Attribute("end");
272225
if (end)
273-
_executableblocks.at(extension).setEnd(end);
226+
_executableblocks[extension].setEnd(end);
274227
const char * offset = librarynode->Attribute("offset");
275228
if (offset)
276-
_executableblocks.at(extension).setOffset(atoi(offset));
229+
_executableblocks[extension].setOffset(atoi(offset));
277230
} else
278231
return false;
279232
}

lib/library.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,8 +39,6 @@
3939
class CPPCHECKLIB Library {
4040
public:
4141
Library();
42-
Library(const Library &);
43-
~Library();
4442

4543
bool load(const char exename [], const char path []);
4644

0 commit comments

Comments
 (0)