Revise implementation of case-insensitive command names

Store both the as-written and lower-case command names and use
the latter to avoid case-insensitive string comparisons.

With this I obtain 2-6% speed increase (on Windows) for the configure
step with no significant changes in memory usage.  A case-insensitive
comparison is a lot slower than just calling `==` because the operator
will use things like memcmp, so prefer the latter.

The `cmSystemTools::LowerCase` function allocates a new string each time
it is called, so before this change we were allocating in:

* cmMakefile::Configure two times for each function
  (to look for `cmake_minimum_required` and `project`)
* cmMakefile::ExecuteCommand twice by function by calling
  cmState::GetCommand and copying the name

Now we are only allocating once by function instead of four.
This commit is contained in:
Florian Jacomme
2018-05-01 16:17:31 +02:00
committed by Brad King
parent 743f24bac6
commit b1a05d6c76
10 changed files with 64 additions and 41 deletions

View File

@@ -23,11 +23,22 @@ class cmMessenger;
struct cmCommandContext
{
std::string Name;
struct cmCommandName
{
std::string Lower;
std::string Original;
cmCommandName() {}
cmCommandName(std::string const& name) { *this = name; }
cmCommandName& operator=(std::string const& name);
} Name;
long Line;
cmCommandContext()
: Name()
, Line(0)
: Line(0)
{
}
cmCommandContext(const char* name, int line)
: Name(name)
, Line(line)
{
}
};
@@ -81,7 +92,7 @@ public:
cmListFileContext lfc;
lfc.FilePath = fileName;
lfc.Line = lfcc.Line;
lfc.Name = lfcc.Name;
lfc.Name = lfcc.Name.Original;
return lfc;
}
};