mirror of
https://github.com/Kitware/CMake.git
synced 2026-05-03 21:00:01 -05:00
use cm::string_view for language extension lookups
Once the list of extensions is build the set is just a copy of the vector and not modified anymore. Use a string_view for the members of the set, which saves a small amount of memory. It also makes possible to use string_views as lookup keys, so the callers do not need to create copies for the extensions anymore.
This commit is contained in:
@@ -6,6 +6,8 @@
|
|||||||
#include <cstddef>
|
#include <cstddef>
|
||||||
#include <utility>
|
#include <utility>
|
||||||
|
|
||||||
|
#include <cm/string_view>
|
||||||
|
|
||||||
#include "cmsys/Directory.hxx"
|
#include "cmsys/Directory.hxx"
|
||||||
|
|
||||||
#include "cmExecutionStatus.h"
|
#include "cmExecutionStatus.h"
|
||||||
@@ -50,11 +52,10 @@ bool cmAuxSourceDirectoryCommand(std::vector<std::string> const& args,
|
|||||||
// Split the filename into base and extension
|
// Split the filename into base and extension
|
||||||
std::string::size_type dotpos = file.rfind('.');
|
std::string::size_type dotpos = file.rfind('.');
|
||||||
if (dotpos != std::string::npos) {
|
if (dotpos != std::string::npos) {
|
||||||
std::string ext = file.substr(dotpos + 1);
|
auto ext = cm::string_view(file).substr(dotpos + 1);
|
||||||
std::string base = file.substr(0, dotpos);
|
|
||||||
// Process only source files
|
// Process only source files
|
||||||
auto cm = mf.GetCMakeInstance();
|
auto cm = mf.GetCMakeInstance();
|
||||||
if (!base.empty() && cm->IsSourceExtension(ext)) {
|
if (dotpos > 0 && cm->IsSourceExtension(ext)) {
|
||||||
std::string fullname = cmStrCat(templateDirectory, '/', file);
|
std::string fullname = cmStrCat(templateDirectory, '/', file);
|
||||||
// add the file as a class file so
|
// add the file as a class file so
|
||||||
// depends can be done
|
// depends can be done
|
||||||
|
|||||||
@@ -4,6 +4,8 @@
|
|||||||
|
|
||||||
#include <cassert>
|
#include <cassert>
|
||||||
|
|
||||||
|
#include <cm/string_view>
|
||||||
|
|
||||||
#include "cmGlobalGenerator.h"
|
#include "cmGlobalGenerator.h"
|
||||||
#include "cmMakefile.h"
|
#include "cmMakefile.h"
|
||||||
#include "cmMessageType.h"
|
#include "cmMessageType.h"
|
||||||
@@ -152,7 +154,7 @@ bool cmSourceFileLocation::MatchesAmbiguousExtension(
|
|||||||
|
|
||||||
// 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 const& ext = this->Name.substr(loc.Name.size() + 1);
|
auto ext = cm::string_view(this->Name).substr(loc.Name.size() + 1);
|
||||||
cmMakefile const* mf = this->Makefile;
|
cmMakefile const* mf = this->Makefile;
|
||||||
auto cm = mf->GetCMakeInstance();
|
auto cm = mf->GetCMakeInstance();
|
||||||
return cm->IsSourceExtension(ext) || cm->IsHeaderExtension(ext);
|
return cm->IsSourceExtension(ext) || cm->IsHeaderExtension(ext);
|
||||||
|
|||||||
+3
-2
@@ -1978,9 +1978,10 @@ std::string cmake::StripExtension(const std::string& file) const
|
|||||||
{
|
{
|
||||||
auto dotpos = file.rfind('.');
|
auto dotpos = file.rfind('.');
|
||||||
if (dotpos != std::string::npos) {
|
if (dotpos != std::string::npos) {
|
||||||
auto ext = file.substr(dotpos + 1);
|
|
||||||
#if defined(_WIN32) || defined(__APPLE__)
|
#if defined(_WIN32) || defined(__APPLE__)
|
||||||
ext = cmSystemTools::LowerCase(ext);
|
auto ext = cmSystemTools::LowerCase(file.substr(dotpos + 1));
|
||||||
|
#else
|
||||||
|
auto ext = cm::string_view(file).substr(dotpos + 1);
|
||||||
#endif
|
#endif
|
||||||
if (this->IsSourceExtension(ext) || this->IsHeaderExtension(ext)) {
|
if (this->IsSourceExtension(ext) || this->IsHeaderExtension(ext)) {
|
||||||
return file.substr(0, dotpos);
|
return file.substr(0, dotpos);
|
||||||
|
|||||||
+8
-6
@@ -16,6 +16,8 @@
|
|||||||
#include <utility>
|
#include <utility>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
||||||
|
#include <cm/string_view>
|
||||||
|
|
||||||
#include "cmGeneratedFileStream.h"
|
#include "cmGeneratedFileStream.h"
|
||||||
#include "cmInstalledFile.h"
|
#include "cmInstalledFile.h"
|
||||||
#include "cmListFileCache.h"
|
#include "cmListFileCache.h"
|
||||||
@@ -138,13 +140,13 @@ public:
|
|||||||
|
|
||||||
struct FileExtensions
|
struct FileExtensions
|
||||||
{
|
{
|
||||||
bool Test(std::string const& ext) const
|
bool Test(cm::string_view ext) const
|
||||||
{
|
{
|
||||||
return (this->unordered.find(ext) != this->unordered.end());
|
return (this->unordered.find(ext) != this->unordered.end());
|
||||||
}
|
}
|
||||||
|
|
||||||
std::vector<std::string> ordered;
|
std::vector<std::string> ordered;
|
||||||
std::unordered_set<std::string> unordered;
|
std::unordered_set<cm::string_view> unordered;
|
||||||
};
|
};
|
||||||
|
|
||||||
using InstalledFilesMap = std::map<std::string, cmInstalledFile>;
|
using InstalledFilesMap = std::map<std::string, cmInstalledFile>;
|
||||||
@@ -266,7 +268,7 @@ public:
|
|||||||
return this->SourceFileExtensions.ordered;
|
return this->SourceFileExtensions.ordered;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool IsSourceExtension(const std::string& ext) const
|
bool IsSourceExtension(cm::string_view ext) const
|
||||||
{
|
{
|
||||||
return this->SourceFileExtensions.Test(ext);
|
return this->SourceFileExtensions.Test(ext);
|
||||||
}
|
}
|
||||||
@@ -276,7 +278,7 @@ public:
|
|||||||
return this->HeaderFileExtensions.ordered;
|
return this->HeaderFileExtensions.ordered;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool IsHeaderExtension(const std::string& ext) const
|
bool IsHeaderExtension(cm::string_view ext) const
|
||||||
{
|
{
|
||||||
return this->HeaderFileExtensions.Test(ext);
|
return this->HeaderFileExtensions.Test(ext);
|
||||||
}
|
}
|
||||||
@@ -286,7 +288,7 @@ public:
|
|||||||
return this->CudaFileExtensions.ordered;
|
return this->CudaFileExtensions.ordered;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool IsCudaExtension(const std::string& ext) const
|
bool IsCudaExtension(cm::string_view ext) const
|
||||||
{
|
{
|
||||||
return this->CudaFileExtensions.Test(ext);
|
return this->CudaFileExtensions.Test(ext);
|
||||||
}
|
}
|
||||||
@@ -296,7 +298,7 @@ public:
|
|||||||
return this->FortranFileExtensions.ordered;
|
return this->FortranFileExtensions.ordered;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool IsFortranExtension(const std::string& ext) const
|
bool IsFortranExtension(cm::string_view ext) const
|
||||||
{
|
{
|
||||||
return this->FortranFileExtensions.Test(ext);
|
return this->FortranFileExtensions.Test(ext);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user