List:MySQL++« Previous MessageNext Message »
From:Dan Grubbs Date:November 14 2017 7:22pm
Subject:Faster
View as plain text  
I was profiling a program of ours that uses mysql++ and found that I could
speed everything up with a simple change to one function.

Changing the FieldNames::operator [](const std::string& s) from :

unsigned int
FieldNames::operator [](const std::string& s) const
{
std::string temp1(s);
internal::str_to_lwr(temp1);
for (const_iterator it = begin(); it != end(); ++it) {
std::string temp2(*it);
internal::str_to_lwr(temp2);
if (temp2.compare(temp1) == 0) {
return it - begin();
}
}

return end() - begin();
}

to:

unsigned int
FieldNames::operator [](const std::string& s) const
{
for (const_iterator it = begin(); it != end(); ++it)
{
std::string temp(*it);
if(s.length() != temp.length())
{
continue;
}
for(int i=0;i<s.length();i++)
{
if(tolower(s[i]) != tolower(temp[i]))
{
continue;
}
}
}

return end() - begin();
}

This does the same thing, but much faster. I could add it myself but I am
not a developer.

Daniel Grubbs

Thread
FasterDan Grubbs14 Nov 2017
Re: FasterWarren Young23 Nov 2017