From 9b5cc4253135c7811936b05525e013e04a390d02 Mon Sep 17 00:00:00 2001 From: Sebastian Holtermann Date: Fri, 19 Jul 2019 10:38:54 +0200 Subject: cmDefinitions: Remove const char* based Set method - Removes `cmDefinitions::Set` method overload that takes a `const char*` value argument. - Updates calls to `cmDefinitions::Set` to use the `cm::string_view` based version instead. --- Source/cmDefinitions.h | 10 ---------- Source/cmState.cxx | 4 ++-- Source/cmStateSnapshot.cxx | 12 ++++++++---- Source/cmStateSnapshot.h | 4 +++- 4 files changed, 13 insertions(+), 17 deletions(-) diff --git a/Source/cmDefinitions.h b/Source/cmDefinitions.h index b6a08bc..4d8810a 100644 --- a/Source/cmDefinitions.h +++ b/Source/cmDefinitions.h @@ -32,16 +32,6 @@ public: static bool HasKey(const std::string& key, StackIter begin, StackIter end); - /** Set (or unset if null) a value associated with a key. */ - void Set(const std::string& key, const char* value) - { - if (value) { - this->Set(key, cm::string_view(value)); - } else { - this->Unset(key); - } - } - /** Set a value associated with a key. */ void Set(const std::string& key, cm::string_view value); diff --git a/Source/cmState.cxx b/Source/cmState.cxx index 0b12a65..6f9c935 100644 --- a/Source/cmState.cxx +++ b/Source/cmState.cxx @@ -308,8 +308,8 @@ cmStateSnapshot cmState::Reset() pos->Parent = this->VarTree.Root(); pos->Root = this->VarTree.Root(); - pos->Vars->Set("CMAKE_SOURCE_DIR", srcDir.c_str()); - pos->Vars->Set("CMAKE_BINARY_DIR", binDir.c_str()); + pos->Vars->Set("CMAKE_SOURCE_DIR", srcDir); + pos->Vars->Set("CMAKE_BINARY_DIR", binDir); } this->DefineProperty("RULE_LAUNCH_COMPILE", cmProperty::DIRECTORY, "", "", diff --git a/Source/cmStateSnapshot.cxx b/Source/cmStateSnapshot.cxx index 63bec71..110ec56 100644 --- a/Source/cmStateSnapshot.cxx +++ b/Source/cmStateSnapshot.cxx @@ -222,14 +222,14 @@ bool cmStateSnapshot::IsInitialized(std::string const& name) const } void cmStateSnapshot::SetDefinition(std::string const& name, - std::string const& value) + cm::string_view value) { - this->Position->Vars->Set(name, value.c_str()); + this->Position->Vars->Set(name, value); } void cmStateSnapshot::RemoveDefinition(std::string const& name) { - this->Position->Vars->Set(name, nullptr); + this->Position->Vars->Unset(name); } std::vector cmStateSnapshot::UnusedKeys() const @@ -264,7 +264,11 @@ bool cmStateSnapshot::RaiseScope(std::string const& var, const char* varDef) cmDefinitions::Raise(var, this->Position->Vars, this->Position->Root); // Now update the definition in the parent scope. - this->Position->Parent->Set(var, varDef); + if (varDef) { + this->Position->Parent->Set(var, varDef); + } else { + this->Position->Parent->Unset(var); + } return true; } diff --git a/Source/cmStateSnapshot.h b/Source/cmStateSnapshot.h index c315f48..da39127 100644 --- a/Source/cmStateSnapshot.h +++ b/Source/cmStateSnapshot.h @@ -9,6 +9,8 @@ #include #include +#include "cm_string_view.hxx" + #include "cmLinkedTree.h" #include "cmPolicies.h" #include "cmStateTypes.h" @@ -24,7 +26,7 @@ public: std::string const* GetDefinition(std::string const& name) const; bool IsInitialized(std::string const& name) const; - void SetDefinition(std::string const& name, std::string const& value); + void SetDefinition(std::string const& name, cm::string_view value); void RemoveDefinition(std::string const& name); std::vector UnusedKeys() const; std::vector ClosureKeys() const; -- cgit v0.12