Merge topic 'dev/source-file-performance'

77b37965 cmSourceFile: Take a string
7b8a9904 perf: Cache the language property string
10baf00f cmSourceFile: Cache the isUiFile check
14e7a8ae cmSourceFileLocation: Return a string reference
b4cb543e cmSourceFileLocation: Save some string copies
e8e1f3a1 cmSourceFileLocation: Simplify logic in Matches
5554910e cmSourceFileLocation: Avoid string allocation in extension checking
This commit is contained in:
Brad King 2014-05-07 15:59:49 -04:00 committed by CMake Topic Stage
commit b80928f0ae
4 changed files with 61 additions and 56 deletions

View File

@ -24,6 +24,8 @@ cmSourceFile::cmSourceFile(cmMakefile* mf, const std::string& name):
this->CustomCommand = 0; this->CustomCommand = 0;
this->Properties.SetCMakeInstance(mf->GetCMakeInstance()); this->Properties.SetCMakeInstance(mf->GetCMakeInstance());
this->FindFullPathFailed = false; this->FindFullPathFailed = false;
this->IsUiFile = ("ui" ==
cmSystemTools::GetFilenameLastExtension(this->Location.GetName()));
} }
//---------------------------------------------------------------------------- //----------------------------------------------------------------------------
@ -38,6 +40,8 @@ std::string const& cmSourceFile::GetExtension() const
return this->Extension; return this->Extension;
} }
const std::string cmSourceFile::propLANGUAGE = "LANGUAGE";
//---------------------------------------------------------------------------- //----------------------------------------------------------------------------
void cmSourceFile::SetObjectLibrary(std::string const& objlib) void cmSourceFile::SetObjectLibrary(std::string const& objlib)
{ {
@ -54,7 +58,7 @@ std::string cmSourceFile::GetObjectLibrary() const
std::string cmSourceFile::GetLanguage() std::string cmSourceFile::GetLanguage()
{ {
// If the language was set explicitly by the user then use it. // If the language was set explicitly by the user then use it.
if(const char* lang = this->GetProperty("LANGUAGE")) if(const char* lang = this->GetProperty(propLANGUAGE))
{ {
return lang; return lang;
} }
@ -91,7 +95,7 @@ std::string cmSourceFile::GetLanguage()
std::string cmSourceFile::GetLanguage() const std::string cmSourceFile::GetLanguage() const
{ {
// If the language was set explicitly by the user then use it. // If the language was set explicitly by the user then use it.
if(const char* lang = this->GetProperty("LANGUAGE")) if(const char* lang = this->GetProperty(propLANGUAGE))
{ {
return lang; return lang;
} }
@ -297,9 +301,7 @@ void cmSourceFile::SetProperty(const std::string& prop, const char* value)
{ {
this->Properties.SetProperty(prop, value, cmProperty::SOURCE_FILE); this->Properties.SetProperty(prop, value, cmProperty::SOURCE_FILE);
std::string ext = if (this->IsUiFile)
cmSystemTools::GetFilenameLastExtension(this->Location.GetName());
if (ext == ".ui")
{ {
cmMakefile const* mf = this->Location.GetMakefile(); cmMakefile const* mf = this->Location.GetMakefile();
if (prop == "AUTOUIC_OPTIONS") if (prop == "AUTOUIC_OPTIONS")

View File

@ -86,7 +86,7 @@ public:
* Return the vector that holds the list of dependencies * Return the vector that holds the list of dependencies
*/ */
const std::vector<std::string> &GetDepends() const {return this->Depends;} const std::vector<std::string> &GetDepends() const {return this->Depends;}
void AddDepend(const char* d) { this->Depends.push_back(d); } void AddDepend(const std::string& d) { this->Depends.push_back(d); }
// Get the properties // Get the properties
cmPropertyMap &GetProperties() { return this->Properties; } cmPropertyMap &GetProperties() { return this->Properties; }
@ -109,6 +109,7 @@ private:
std::string FullPath; std::string FullPath;
bool FindFullPathFailed; bool FindFullPathFailed;
std::string ObjectLibrary; std::string ObjectLibrary;
bool IsUiFile;
bool FindFullPath(std::string* error); bool FindFullPath(std::string* error);
bool TryFullPath(const std::string& path, const std::string& ext); bool TryFullPath(const std::string& path, const std::string& ext);
@ -116,6 +117,8 @@ private:
void CheckLanguage(std::string const& ext); void CheckLanguage(std::string const& ext);
std::vector<std::string> Depends; std::vector<std::string> Depends;
static const std::string propLANGUAGE;
}; };
// TODO: Factor out into platform information modules. // TODO: Factor out into platform information modules.

View File

@ -183,15 +183,16 @@ cmSourceFileLocation
// Check if loc's name could possibly be extended to our name by // Check if loc's name could possibly be extended to our name by
// adding an extension. // adding an extension.
if(!(this->Name.size() > loc.Name.size() && if(!(this->Name.size() > loc.Name.size() &&
this->Name.substr(0, loc.Name.size()) == loc.Name && this->Name[loc.Name.size()] == '.' &&
this->Name[loc.Name.size()] == '.')) cmHasLiteralPrefixImpl(this->Name.c_str(),
loc.Name.c_str(), loc.Name.size())))
{ {
return false; return false;
} }
// Only a fixed set of extensions will be tried to match a file on // Only a fixed set of extensions will be tried to match a file on
// disk. One of these must match if loc refers to this source file. // disk. One of these must match if loc refers to this source file.
std::string ext = this->Name.substr(loc.Name.size()+1); std::string const& ext = this->Name.substr(loc.Name.size()+1);
cmMakefile const* mf = this->Makefile; cmMakefile const* mf = this->Makefile;
const std::vector<std::string>& srcExts = mf->GetSourceExtensions(); const std::vector<std::string>& srcExts = mf->GetSourceExtensions();
if(std::find(srcExts.begin(), srcExts.end(), ext) != srcExts.end()) if(std::find(srcExts.begin(), srcExts.end(), ext) != srcExts.end())
@ -210,36 +211,33 @@ cmSourceFileLocation
bool cmSourceFileLocation::Matches(cmSourceFileLocation const& loc) bool cmSourceFileLocation::Matches(cmSourceFileLocation const& loc)
{ {
assert(this->Makefile); assert(this->Makefile);
if(this->AmbiguousExtension && loc.AmbiguousExtension) if(this->AmbiguousExtension == loc.AmbiguousExtension)
{ {
// Both extensions are ambiguous. Since only the old fixed set of // Both extensions are similarly ambiguous. Since only the old fixed set
// extensions will be tried, the names must match at this point to // of extensions will be tried, the names must match at this point to be
// be the same file. // the same file.
if(this->Name != loc.Name) if(this->Name.size() != loc.Name.size() || this->Name != loc.Name)
{
return false;
}
}
else if(this->AmbiguousExtension)
{
// Only "this" extension is ambiguous.
if(!loc.MatchesAmbiguousExtension(*this))
{
return false;
}
}
else if(loc.AmbiguousExtension)
{
// Only "loc" extension is ambiguous.
if(!this->MatchesAmbiguousExtension(loc))
{ {
return false; return false;
} }
} }
else else
{ {
// Neither extension is ambiguous. const cmSourceFileLocation* loc1;
if(this->Name != loc.Name) const cmSourceFileLocation* loc2;
if(this->AmbiguousExtension)
{
// Only "this" extension is ambiguous.
loc1 = &loc;
loc2 = this;
}
else
{
// Only "loc" extension is ambiguous.
loc1 = this;
loc2 = &loc;
}
if(!loc1->MatchesAmbiguousExtension(*loc2))
{ {
return false; return false;
} }
@ -253,35 +251,37 @@ bool cmSourceFileLocation::Matches(cmSourceFileLocation const& loc)
return false; return false;
} }
} }
else if(this->AmbiguousDirectory && loc.AmbiguousDirectory &&
this->Makefile == loc.Makefile)
{
// Both sides have directories relative to the same location.
if(this->Directory != loc.Directory)
{
return false;
}
}
else if(this->AmbiguousDirectory && loc.AmbiguousDirectory) else if(this->AmbiguousDirectory && loc.AmbiguousDirectory)
{ {
// Each side has a directory relative to a different location. if (this->Makefile == loc.Makefile)
// This can occur when referencing a source file from a different {
// directory. This is not yet allowed. // Both sides have directories relative to the same location.
this->Makefile->IssueMessage( if(this->Directory != loc.Directory)
cmake::INTERNAL_ERROR, {
"Matches error: Each side has a directory relative to a different " return false;
"location. This can occur when referencing a source file from a " }
"different directory. This is not yet allowed." }
); else
return false; {
// Each side has a directory relative to a different location.
// This can occur when referencing a source file from a different
// directory. This is not yet allowed.
this->Makefile->IssueMessage(
cmake::INTERNAL_ERROR,
"Matches error: Each side has a directory relative to a different "
"location. This can occur when referencing a source file from a "
"different directory. This is not yet allowed."
);
return false;
}
} }
else if(this->AmbiguousDirectory) else if(this->AmbiguousDirectory)
{ {
// Compare possible directory combinations. // Compare possible directory combinations.
std::string srcDir = std::string const& srcDir =
cmSystemTools::CollapseFullPath( cmSystemTools::CollapseFullPath(
this->Directory.c_str(), this->Makefile->GetCurrentDirectory()); this->Directory.c_str(), this->Makefile->GetCurrentDirectory());
std::string binDir = std::string const& binDir =
cmSystemTools::CollapseFullPath( cmSystemTools::CollapseFullPath(
this->Directory.c_str(), this->Makefile->GetCurrentOutputDirectory()); this->Directory.c_str(), this->Makefile->GetCurrentOutputDirectory());
if(srcDir != loc.Directory && if(srcDir != loc.Directory &&
@ -293,10 +293,10 @@ bool cmSourceFileLocation::Matches(cmSourceFileLocation const& loc)
else if(loc.AmbiguousDirectory) else if(loc.AmbiguousDirectory)
{ {
// Compare possible directory combinations. // Compare possible directory combinations.
std::string srcDir = std::string const& srcDir =
cmSystemTools::CollapseFullPath( cmSystemTools::CollapseFullPath(
loc.Directory.c_str(), loc.Makefile->GetCurrentDirectory()); loc.Directory.c_str(), loc.Makefile->GetCurrentDirectory());
std::string binDir = std::string const& binDir =
cmSystemTools::CollapseFullPath( cmSystemTools::CollapseFullPath(
loc.Directory.c_str(), loc.Makefile->GetCurrentOutputDirectory()); loc.Directory.c_str(), loc.Makefile->GetCurrentOutputDirectory());
if(srcDir != this->Directory && if(srcDir != this->Directory &&

View File

@ -71,7 +71,7 @@ public:
* Otherwise it will be a relative path (possibly empty) that is * Otherwise it will be a relative path (possibly empty) that is
* either with respect to the source or build tree. * either with respect to the source or build tree.
*/ */
const char* GetDirectory() const { return this->Directory.c_str(); } const std::string& GetDirectory() const { return this->Directory; }
/** /**
* Get the file name as best is currently known. If * Get the file name as best is currently known. If