浏览代码

Refactor: Use string view

Alex Turbov 4 年之前
父节点
当前提交
f9947ec9e3
共有 1 个文件被更改,包括 31 次插入29 次删除
  1. 31 29
      Source/cmCMakeHostSystemInformationCommand.cxx

+ 31 - 29
Source/cmCMakeHostSystemInformationCommand.cxx

@@ -5,6 +5,8 @@
 #include <cstddef>
 #include <cstddef>
 
 
 #include <cm/optional>
 #include <cm/optional>
+#include <cm/string_view>
+#include <cmext/string_view>
 
 
 #include "cmsys/SystemInformation.hxx"
 #include "cmsys/SystemInformation.hxx"
 
 
@@ -40,96 +42,96 @@ std::string ValueToString(std::string const& value)
 cm::optional<std::string> GetValue(cmsys::SystemInformation& info,
 cm::optional<std::string> GetValue(cmsys::SystemInformation& info,
                                    std::string const& key)
                                    std::string const& key)
 {
 {
-  if (key == "NUMBER_OF_LOGICAL_CORES") {
+  if (key == "NUMBER_OF_LOGICAL_CORES"_s) {
     return ValueToString(info.GetNumberOfLogicalCPU());
     return ValueToString(info.GetNumberOfLogicalCPU());
   }
   }
-  if (key == "NUMBER_OF_PHYSICAL_CORES") {
+  if (key == "NUMBER_OF_PHYSICAL_CORES"_s) {
     return ValueToString(info.GetNumberOfPhysicalCPU());
     return ValueToString(info.GetNumberOfPhysicalCPU());
   }
   }
-  if (key == "HOSTNAME") {
+  if (key == "HOSTNAME"_s) {
     return ValueToString(info.GetHostname());
     return ValueToString(info.GetHostname());
   }
   }
-  if (key == "FQDN") {
+  if (key == "FQDN"_s) {
     return ValueToString(info.GetFullyQualifiedDomainName());
     return ValueToString(info.GetFullyQualifiedDomainName());
   }
   }
-  if (key == "TOTAL_VIRTUAL_MEMORY") {
+  if (key == "TOTAL_VIRTUAL_MEMORY"_s) {
     return ValueToString(info.GetTotalVirtualMemory());
     return ValueToString(info.GetTotalVirtualMemory());
   }
   }
-  if (key == "AVAILABLE_VIRTUAL_MEMORY") {
+  if (key == "AVAILABLE_VIRTUAL_MEMORY"_s) {
     return ValueToString(info.GetAvailableVirtualMemory());
     return ValueToString(info.GetAvailableVirtualMemory());
   }
   }
-  if (key == "TOTAL_PHYSICAL_MEMORY") {
+  if (key == "TOTAL_PHYSICAL_MEMORY"_s) {
     return ValueToString(info.GetTotalPhysicalMemory());
     return ValueToString(info.GetTotalPhysicalMemory());
   }
   }
-  if (key == "AVAILABLE_PHYSICAL_MEMORY") {
+  if (key == "AVAILABLE_PHYSICAL_MEMORY"_s) {
     return ValueToString(info.GetAvailablePhysicalMemory());
     return ValueToString(info.GetAvailablePhysicalMemory());
   }
   }
-  if (key == "IS_64BIT") {
+  if (key == "IS_64BIT"_s) {
     return ValueToString(info.Is64Bits());
     return ValueToString(info.Is64Bits());
   }
   }
-  if (key == "HAS_FPU") {
+  if (key == "HAS_FPU"_s) {
     return ValueToString(
     return ValueToString(
       info.DoesCPUSupportFeature(cmsys::SystemInformation::CPU_FEATURE_FPU));
       info.DoesCPUSupportFeature(cmsys::SystemInformation::CPU_FEATURE_FPU));
   }
   }
-  if (key == "HAS_MMX") {
+  if (key == "HAS_MMX"_s) {
     return ValueToString(
     return ValueToString(
       info.DoesCPUSupportFeature(cmsys::SystemInformation::CPU_FEATURE_MMX));
       info.DoesCPUSupportFeature(cmsys::SystemInformation::CPU_FEATURE_MMX));
   }
   }
-  if (key == "HAS_MMX_PLUS") {
+  if (key == "HAS_MMX_PLUS"_s) {
     return ValueToString(info.DoesCPUSupportFeature(
     return ValueToString(info.DoesCPUSupportFeature(
       cmsys::SystemInformation::CPU_FEATURE_MMX_PLUS));
       cmsys::SystemInformation::CPU_FEATURE_MMX_PLUS));
   }
   }
-  if (key == "HAS_SSE") {
+  if (key == "HAS_SSE"_s) {
     return ValueToString(
     return ValueToString(
       info.DoesCPUSupportFeature(cmsys::SystemInformation::CPU_FEATURE_SSE));
       info.DoesCPUSupportFeature(cmsys::SystemInformation::CPU_FEATURE_SSE));
   }
   }
-  if (key == "HAS_SSE2") {
+  if (key == "HAS_SSE2"_s) {
     return ValueToString(
     return ValueToString(
       info.DoesCPUSupportFeature(cmsys::SystemInformation::CPU_FEATURE_SSE2));
       info.DoesCPUSupportFeature(cmsys::SystemInformation::CPU_FEATURE_SSE2));
   }
   }
-  if (key == "HAS_SSE_FP") {
+  if (key == "HAS_SSE_FP"_s) {
     return ValueToString(info.DoesCPUSupportFeature(
     return ValueToString(info.DoesCPUSupportFeature(
       cmsys::SystemInformation::CPU_FEATURE_SSE_FP));
       cmsys::SystemInformation::CPU_FEATURE_SSE_FP));
   }
   }
-  if (key == "HAS_SSE_MMX") {
+  if (key == "HAS_SSE_MMX"_s) {
     return ValueToString(info.DoesCPUSupportFeature(
     return ValueToString(info.DoesCPUSupportFeature(
       cmsys::SystemInformation::CPU_FEATURE_SSE_MMX));
       cmsys::SystemInformation::CPU_FEATURE_SSE_MMX));
   }
   }
-  if (key == "HAS_AMD_3DNOW") {
+  if (key == "HAS_AMD_3DNOW"_s) {
     return ValueToString(info.DoesCPUSupportFeature(
     return ValueToString(info.DoesCPUSupportFeature(
       cmsys::SystemInformation::CPU_FEATURE_AMD_3DNOW));
       cmsys::SystemInformation::CPU_FEATURE_AMD_3DNOW));
   }
   }
-  if (key == "HAS_AMD_3DNOW_PLUS") {
+  if (key == "HAS_AMD_3DNOW_PLUS"_s) {
     return ValueToString(info.DoesCPUSupportFeature(
     return ValueToString(info.DoesCPUSupportFeature(
       cmsys::SystemInformation::CPU_FEATURE_AMD_3DNOW_PLUS));
       cmsys::SystemInformation::CPU_FEATURE_AMD_3DNOW_PLUS));
   }
   }
-  if (key == "HAS_IA64") {
+  if (key == "HAS_IA64"_s) {
     return ValueToString(
     return ValueToString(
       info.DoesCPUSupportFeature(cmsys::SystemInformation::CPU_FEATURE_IA64));
       info.DoesCPUSupportFeature(cmsys::SystemInformation::CPU_FEATURE_IA64));
   }
   }
-  if (key == "HAS_SERIAL_NUMBER") {
+  if (key == "HAS_SERIAL_NUMBER"_s) {
     return ValueToString(info.DoesCPUSupportFeature(
     return ValueToString(info.DoesCPUSupportFeature(
       cmsys::SystemInformation::CPU_FEATURE_SERIALNUMBER));
       cmsys::SystemInformation::CPU_FEATURE_SERIALNUMBER));
   }
   }
-  if (key == "PROCESSOR_NAME") {
+  if (key == "PROCESSOR_NAME"_s) {
     return ValueToString(info.GetExtendedProcessorName());
     return ValueToString(info.GetExtendedProcessorName());
   }
   }
-  if (key == "PROCESSOR_DESCRIPTION") {
+  if (key == "PROCESSOR_DESCRIPTION"_s) {
     return info.GetCPUDescription();
     return info.GetCPUDescription();
   }
   }
-  if (key == "PROCESSOR_SERIAL_NUMBER") {
+  if (key == "PROCESSOR_SERIAL_NUMBER"_s) {
     return ValueToString(info.GetProcessorSerialNumber());
     return ValueToString(info.GetProcessorSerialNumber());
   }
   }
-  if (key == "OS_NAME") {
+  if (key == "OS_NAME"_s) {
     return ValueToString(info.GetOSName());
     return ValueToString(info.GetOSName());
   }
   }
-  if (key == "OS_RELEASE") {
+  if (key == "OS_RELEASE"_s) {
     return ValueToString(info.GetOSRelease());
     return ValueToString(info.GetOSRelease());
   }
   }
-  if (key == "OS_VERSION") {
+  if (key == "OS_VERSION"_s) {
     return ValueToString(info.GetOSVersion());
     return ValueToString(info.GetOSVersion());
   }
   }
-  if (key == "OS_PLATFORM") {
+  if (key == "OS_PLATFORM"_s) {
     return ValueToString(info.GetOSPlatform());
     return ValueToString(info.GetOSPlatform());
   }
   }
   return {};
   return {};
@@ -205,7 +207,7 @@ bool cmCMakeHostSystemInformationCommand(std::vector<std::string> const& args,
 {
 {
   std::size_t current_index = 0;
   std::size_t current_index = 0;
 
 
-  if (args.size() < (current_index + 2) || args[current_index] != "RESULT") {
+  if (args.size() < (current_index + 2) || args[current_index] != "RESULT"_s) {
     status.SetError("missing RESULT specification.");
     status.SetError("missing RESULT specification.");
     return false;
     return false;
   }
   }
@@ -213,7 +215,7 @@ bool cmCMakeHostSystemInformationCommand(std::vector<std::string> const& args,
   auto const& variable = args[current_index + 1];
   auto const& variable = args[current_index + 1];
   current_index += 2;
   current_index += 2;
 
 
-  if (args.size() < (current_index + 2) || args[current_index] != "QUERY") {
+  if (args.size() < (current_index + 2) || args[current_index] != "QUERY"_s) {
     status.SetError("missing QUERY specification");
     status.SetError("missing QUERY specification");
     return false;
     return false;
   }
   }