Skip to content

Commit 03708d2

Browse files
committed
[AST] Rework isSDKModule with a different algorithm
1 parent ac704e4 commit 03708d2

File tree

1 file changed

+12
-7
lines changed

1 file changed

+12
-7
lines changed

lib/AST/Module.cpp

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1997,15 +1997,20 @@ StringRef ModuleDecl::getModuleLoadedFilename() const {
19971997
}
19981998

19991999
bool ModuleDecl::isSDKModule() const {
2000-
if (getASTContext().SearchPathOpts.getSDKPath().empty())
2000+
auto sdkPath = getASTContext().SearchPathOpts.getSDKPath();
2001+
if (sdkPath.empty())
20012002
return false;
20022003

2003-
auto sdkPath = SmallString<8>(),
2004-
modulePath = SmallString<8>();
2005-
llvm::sys::path::native(getASTContext().SearchPathOpts.getSDKPath(), sdkPath);
2006-
llvm::sys::path::native(getModuleSourceFilename(), modulePath);
2007-
2008-
return modulePath.startswith(sdkPath);
2004+
auto modulePath = getModuleSourceFilename();
2005+
auto si = llvm::sys::path::begin(sdkPath),
2006+
se = llvm::sys::path::end(sdkPath);
2007+
for (auto mi = llvm::sys::path::begin(modulePath),
2008+
me = llvm::sys::path::end(modulePath);
2009+
si != se && mi != me; ++si, ++mi) {
2010+
if (*si != *mi)
2011+
return false;
2012+
}
2013+
return si == se;
20092014
}
20102015

20112016
bool ModuleDecl::isStdlibModule() const {

0 commit comments

Comments
 (0)