From f7f0d6c7560a8f71707e7852a512469147aa9f84 Mon Sep 17 00:00:00 2001 From: David Kalnischkies Date: Thu, 11 Aug 2011 20:53:28 +0200 Subject: cppcheck complains about some possible speed improvements which could be done on the mirco-optimazation level, so lets fix them: (performance) Possible inefficient checking for emptiness. (performance) Prefer prefix ++/-- operators for non-primitive types. --- apt-pkg/contrib/configuration.cc | 6 +++--- apt-pkg/contrib/error.cc | 6 +++--- apt-pkg/contrib/strutl.cc | 30 +++++++++++++++--------------- 3 files changed, 21 insertions(+), 21 deletions(-) (limited to 'apt-pkg/contrib') diff --git a/apt-pkg/contrib/configuration.cc b/apt-pkg/contrib/configuration.cc index 942ea9fbc..ece05e8f6 100644 --- a/apt-pkg/contrib/configuration.cc +++ b/apt-pkg/contrib/configuration.cc @@ -672,9 +672,9 @@ bool ReadConfigFile(Configuration &Conf,const string &FName,bool const &AsSectio // Put the last fragment into the buffer std::string::const_iterator NonWhitespaceStart = Start; std::string::const_iterator NonWhitespaceStop = I; - for (; NonWhitespaceStart != I && isspace(*NonWhitespaceStart) != 0; NonWhitespaceStart++) + for (; NonWhitespaceStart != I && isspace(*NonWhitespaceStart) != 0; ++NonWhitespaceStart) ; - for (; NonWhitespaceStop != NonWhitespaceStart && isspace(NonWhitespaceStop[-1]) != 0; NonWhitespaceStop--) + for (; NonWhitespaceStop != NonWhitespaceStart && isspace(NonWhitespaceStop[-1]) != 0; --NonWhitespaceStop) ; if (LineBuffer.empty() == false && NonWhitespaceStop - NonWhitespaceStart != 0) LineBuffer += ' '; @@ -850,7 +850,7 @@ bool ReadConfigDir(Configuration &Conf,const string &Dir, vector const List = GetListOfFilesInDir(Dir, "conf", true, true); // Read the files - for (vector::const_iterator I = List.begin(); I != List.end(); I++) + for (vector::const_iterator I = List.begin(); I != List.end(); ++I) if (ReadConfigFile(Conf,*I,AsSectional,Depth) == false) return false; return true; diff --git a/apt-pkg/contrib/error.cc b/apt-pkg/contrib/error.cc index 18810d2a4..edb290f34 100644 --- a/apt-pkg/contrib/error.cc +++ b/apt-pkg/contrib/error.cc @@ -193,7 +193,7 @@ bool GlobalError::PopMessage(std::string &Text) { // check if another error message is pending for (std::list::const_iterator m = Messages.begin(); - m != Messages.end(); m++) + m != Messages.end(); ++m) if (m->Type == ERROR || m->Type == FATAL) return Ret; @@ -210,7 +210,7 @@ void GlobalError::DumpErrors(std::ostream &out, MsgType const &threshold, Messages.insert(Messages.begin(), s->Messages.begin(), s->Messages.end()); for (std::list::const_iterator m = Messages.begin(); - m != Messages.end(); m++) + m != Messages.end(); ++m) if (m->Type >= threshold) out << (*m) << std::endl; Discard(); @@ -231,7 +231,7 @@ bool GlobalError::empty(MsgType const &trashhold) const { return true; for (std::list::const_iterator m = Messages.begin(); - m != Messages.end(); m++) + m != Messages.end(); ++m) if (m->Type >= trashhold) return false; diff --git a/apt-pkg/contrib/strutl.cc b/apt-pkg/contrib/strutl.cc index ab2da2d9a..867bb313b 100644 --- a/apt-pkg/contrib/strutl.cc +++ b/apt-pkg/contrib/strutl.cc @@ -271,7 +271,7 @@ bool ParseCWord(const char *&String,string &Res) string QuoteString(const string &Str, const char *Bad) { string Res; - for (string::const_iterator I = Str.begin(); I != Str.end(); I++) + for (string::const_iterator I = Str.begin(); I != Str.end(); ++I) { if (strchr(Bad,*I) != 0 || isprint(*I) == 0 || *I == 0x25 || // percent '%' char @@ -298,7 +298,7 @@ string DeQuoteString(string::const_iterator const &begin, string::const_iterator const &end) { string Res; - for (string::const_iterator I = begin; I != end; I++) + for (string::const_iterator I = begin; I != end; ++I) { if (*I == '%' && I + 2 < end && isxdigit(I[1]) && isxdigit(I[2])) @@ -632,7 +632,7 @@ string LookupTag(const string &Message,const char *Tag,const char *Default) { // Look for a matching tag. int Length = strlen(Tag); - for (string::const_iterator I = Message.begin(); I + Length < Message.end(); I++) + for (string::const_iterator I = Message.begin(); I + Length < Message.end(); ++I) { // Found the tag if (I[Length] == ':' && stringcasecmp(I,I+Length,Tag) == 0) @@ -640,14 +640,14 @@ string LookupTag(const string &Message,const char *Tag,const char *Default) // Find the end of line and strip the leading/trailing spaces string::const_iterator J; I += Length + 1; - for (; isspace(*I) != 0 && I < Message.end(); I++); - for (J = I; *J != '\n' && J < Message.end(); J++); - for (; J > I && isspace(J[-1]) != 0; J--); + for (; isspace(*I) != 0 && I < Message.end(); ++I); + for (J = I; *J != '\n' && J < Message.end(); ++J); + for (; J > I && isspace(J[-1]) != 0; --J); return string(I,J); } - for (; *I != '\n' && I < Message.end(); I++); + for (; *I != '\n' && I < Message.end(); ++I); } // Failed to find a match @@ -1224,7 +1224,7 @@ int tolower_ascii(int const c) bool CheckDomainList(const string &Host,const string &List) { string::const_iterator Start = List.begin(); - for (string::const_iterator Cur = List.begin(); Cur <= List.end(); Cur++) + for (string::const_iterator Cur = List.begin(); Cur <= List.end(); ++Cur) { if (Cur < List.end() && *Cur != ',') continue; @@ -1248,7 +1248,7 @@ string DeEscapeString(const string &input) char tmp[3]; string::const_iterator it, escape_start; string output, octal, hex; - for (it = input.begin(); it != input.end(); it++) + for (it = input.begin(); it != input.end(); ++it) { // just copy non-escape chars if (*it != '\\') @@ -1264,7 +1264,7 @@ string DeEscapeString(const string &input) // copy output += *it; // advance iterator one step further - it += 1; + ++it; continue; } @@ -1273,7 +1273,7 @@ string DeEscapeString(const string &input) continue; // read it - it++; + ++it; switch (*it) { case '0': @@ -1310,7 +1310,7 @@ void URI::CopyFrom(const string &U) string::const_iterator I = U.begin(); // Locate the first colon, this separates the scheme - for (; I < U.end() && *I != ':' ; I++); + for (; I < U.end() && *I != ':' ; ++I); string::const_iterator FirstColon = I; /* Determine if this is a host type URI with a leading double // @@ -1322,7 +1322,7 @@ void URI::CopyFrom(const string &U) /* Find the / indicating the end of the hostname, ignoring /'s in the square brackets */ bool InBracket = false; - for (; SingleSlash < U.end() && (*SingleSlash != '/' || InBracket == true); SingleSlash++) + for (; SingleSlash < U.end() && (*SingleSlash != '/' || InBracket == true); ++SingleSlash) { if (*SingleSlash == '[') InBracket = true; @@ -1355,11 +1355,11 @@ void URI::CopyFrom(const string &U) I = FirstColon + 1; if (I > SingleSlash) I = SingleSlash; - for (; I < SingleSlash && *I != ':'; I++); + for (; I < SingleSlash && *I != ':'; ++I); string::const_iterator SecondColon = I; // Search for the @ after the colon - for (; I < SingleSlash && *I != '@'; I++); + for (; I < SingleSlash && *I != '@'; ++I); string::const_iterator At = I; // Now write the host and user/pass -- cgit v1.2.3 From 91c03d370d36b7a802b841394fb6afdccbd34893 Mon Sep 17 00:00:00 2001 From: David Kalnischkies Date: Thu, 11 Aug 2011 23:01:15 +0200 Subject: fix a few more cppcheck performance and scope warnings --- apt-pkg/contrib/netrc.cc | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) (limited to 'apt-pkg/contrib') diff --git a/apt-pkg/contrib/netrc.cc b/apt-pkg/contrib/netrc.cc index 34f472ee1..9ff5796c5 100644 --- a/apt-pkg/contrib/netrc.cc +++ b/apt-pkg/contrib/netrc.cc @@ -47,10 +47,7 @@ int parsenetrc (char *host, char *login, char *password, char *netrcfile = NULL) int specific_login = (login[0] != 0); char *home = NULL; bool netrc_alloc = false; - int state = NOTHING; - char state_login = 0; /* Found a login keyword */ - char state_password = 0; /* Found a password keyword */ int state_our_login = false; /* With specific_login, found *our* login name */ @@ -81,6 +78,10 @@ int parsenetrc (char *host, char *login, char *password, char *netrcfile = NULL) bool done = false; char netrcbuffer[256]; + int state = NOTHING; + char state_login = 0; /* Found a login keyword */ + char state_password = 0; /* Found a password keyword */ + while (!done && fgets(netrcbuffer, sizeof (netrcbuffer), file)) { tok = strtok_r (netrcbuffer, " \t\n", &tok_buf); while (!done && tok) { -- cgit v1.2.3