forked from OSchip/llvm-project
Speed up isBytecodeLPath from 20s to .01s in common cases. This makes -native
not completely painful to use. Once we decide a directory has a bytecode library, we know it this function returns true, no need to scan entire directories. llvm-svn: 23405
This commit is contained in:
parent
9b9b510084
commit
f20941116b
|
@ -148,49 +148,43 @@ static bool isBytecodeLibrary(const sys::Path &FullPath) {
|
||||||
}
|
}
|
||||||
|
|
||||||
static bool isBytecodeLPath(const std::string &LibPath) {
|
static bool isBytecodeLPath(const std::string &LibPath) {
|
||||||
bool isBytecodeLPath = false;
|
|
||||||
|
|
||||||
sys::Path LPath(LibPath);
|
sys::Path LPath(LibPath);
|
||||||
|
|
||||||
// Make sure it exists
|
// Make sure it exists and is a directory
|
||||||
if (!LPath.exists())
|
|
||||||
return isBytecodeLPath;
|
|
||||||
|
|
||||||
// Make sure its a directory
|
|
||||||
try {
|
try {
|
||||||
if (!LPath.isDirectory())
|
if (!LPath.exists() || !LPath.isDirectory())
|
||||||
return isBytecodeLPath;
|
return false;
|
||||||
} catch (std::string& xcptn) {
|
} catch (std::string& xcptn) {
|
||||||
return isBytecodeLPath;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Grab the contents of the -L path
|
// Grab the contents of the -L path
|
||||||
std::set<sys::Path> Files;
|
std::set<sys::Path> Files;
|
||||||
LPath.getDirectoryContents(Files);
|
LPath.getDirectoryContents(Files);
|
||||||
|
|
||||||
// Iterate over the contents one by one to determine
|
// Iterate over the contents one by one to determine
|
||||||
// if this -L path has any bytecode shared libraries
|
// if this -L path has any bytecode shared libraries
|
||||||
// or archives
|
// or archives
|
||||||
std::set<sys::Path>::iterator File = Files.begin();
|
std::set<sys::Path>::iterator File = Files.begin();
|
||||||
|
std::string dllsuffix = sys::Path::GetDLLSuffix();
|
||||||
for (; File != Files.end(); ++File) {
|
for (; File != Files.end(); ++File) {
|
||||||
|
|
||||||
if ( File->isDirectory() )
|
if ( File->isDirectory() )
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
std::string path = File->toString();
|
std::string path = File->toString();
|
||||||
std::string dllsuffix = sys::Path::GetDLLSuffix();
|
|
||||||
|
|
||||||
// Check for an ending '.dll,.so' or '.a' suffix as all
|
// Check for an ending '.dll,.so' or '.a' suffix as all
|
||||||
// other files are not of interest to us here
|
// other files are not of interest to us here
|
||||||
if ( path.find(dllsuffix, path.size()-dllsuffix.size()) == std::string::npos
|
if (path.find(dllsuffix, path.size()-dllsuffix.size()) == std::string::npos
|
||||||
&& path.find(".a", path.size()-2) == std::string::npos )
|
&& path.find(".a", path.size()-2) == std::string::npos)
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
// Finally, check to see if the file is a true bytecode file
|
// Finally, check to see if the file is a true bytecode file
|
||||||
if (isBytecodeLibrary(*File))
|
if (isBytecodeLibrary(*File))
|
||||||
isBytecodeLPath = true;
|
return true;
|
||||||
}
|
}
|
||||||
return isBytecodeLPath;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// GenerateBytecode - generates a bytecode file from the specified module.
|
/// GenerateBytecode - generates a bytecode file from the specified module.
|
||||||
|
|
Loading…
Reference in New Issue