Skip to content

Commit

Permalink
[external] set absl config to only use std::string_view
Browse files Browse the repository at this point in the history
Cleanup all locations that use absl::string_view
  • Loading branch information
jd28 committed Oct 1, 2024
1 parent 7ef9062 commit 6d985eb
Show file tree
Hide file tree
Showing 11 changed files with 35 additions and 64 deletions.
4 changes: 1 addition & 3 deletions external/abseil-cpp-20240116.1/absl/base/options.h
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,6 @@

#define ABSL_OPTION_USE_STD_ANY 2


// ABSL_OPTION_USE_STD_OPTIONAL
//
// This option controls whether absl::optional is implemented as an alias to
Expand All @@ -123,7 +122,6 @@

#define ABSL_OPTION_USE_STD_OPTIONAL 2


// ABSL_OPTION_USE_STD_STRING_VIEW
//
// This option controls whether absl::string_view is implemented as an alias to
Expand All @@ -148,7 +146,7 @@
// absl::string_view is a typedef of std::string_view, use the feature macro
// ABSL_USES_STD_STRING_VIEW.

#define ABSL_OPTION_USE_STD_STRING_VIEW 2
#define ABSL_OPTION_USE_STD_STRING_VIEW 1

// ABSL_OPTION_USE_STD_VARIANT
//
Expand Down
3 changes: 1 addition & 2 deletions lib/nw/kernel/FactionSystem.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,7 @@ uint32_t FactionSystem::faction_id(std::string_view name) const
{
if (!factions_) { return std::numeric_limits<uint32_t>::max(); }

absl::string_view sv{name.data(), name.size()};
auto it = name_id_map_.find(sv);
auto it = name_id_map_.find(name);
if (it == std::end(name_id_map_)) {
return std::numeric_limits<uint32_t>::max();
}
Expand Down
6 changes: 2 additions & 4 deletions lib/nw/kernel/ModelCache.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,7 @@ void ModelCache::clear()

model::Mdl* ModelCache::load(std::string_view resref)
{
absl::string_view sv{resref.data(), resref.size()};
auto it = map_.find(sv);
auto it = map_.find(resref);
if (it != std::end(map_)) {
++it->second.refcount_;
return it->second.original_.get();
Expand All @@ -38,8 +37,7 @@ model::Mdl* ModelCache::load(std::string_view resref)

void ModelCache::release(std::string_view resref)
{
absl::string_view sv{resref.data(), resref.size()};
auto it = map_.find(sv);
auto it = map_.find(resref);
if (it != std::end(map_)) {
--it->second.refcount_;
if (it->second.refcount_ <= 0) {
Expand Down
3 changes: 1 addition & 2 deletions lib/nw/kernel/Strings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,7 @@ std::string Strings::get(const LocString& locstring, bool feminine) const

InternedString Strings::get_interned(std::string_view str) const
{
absl::string_view sv{str.data(), str.size()};
auto it = interned_.find(sv);
auto it = interned_.find(str);
if (it != std::end(interned_)) {
return InternedString{&*it};
}
Expand Down
2 changes: 0 additions & 2 deletions lib/nw/kernel/TilesetRegistry.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@ void TilesetRegistry::initialize(ServiceInitTime time)

Tileset* TilesetRegistry::load(std::string_view resref)
{
absl::string_view sv{resref.data(), resref.size()};
auto it = tileset_map_.find(resref);
if (it != std::end(tileset_map_)) {
return &it->second;
Expand Down Expand Up @@ -82,7 +81,6 @@ Tileset* TilesetRegistry::load(std::string_view resref)

Tileset* TilesetRegistry::get(std::string_view resref)
{
absl::string_view sv{resref.data(), resref.size()};
auto it = tileset_map_.find(resref);
if (it == std::end(tileset_map_)) {
return nullptr;
Expand Down
50 changes: 17 additions & 33 deletions lib/nw/objects/LocalData.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,7 @@ namespace nw {

void LocalData::clear(std::string_view var, uint32_t type)
{
absl::string_view v{var.data(), var.size()};
auto it = vars_.find(v);
auto it = vars_.find(var);
if (it == std::end(vars_)) {
return;
}
Expand Down Expand Up @@ -44,7 +43,7 @@ void LocalData::clear(std::string_view var, uint32_t type)

void LocalData::clear_all(uint32_t type)
{
static std::vector<absl::string_view> eraser;
static std::vector<std::string_view> eraser;

for (auto& [k, v] : vars_) {
switch (type) {
Expand Down Expand Up @@ -82,8 +81,7 @@ void LocalData::clear_all(uint32_t type)

void LocalData::delete_float(std::string_view var)
{
absl::string_view v{var.data(), var.size()};
auto it = vars_.find(v);
auto it = vars_.find(var);
if (it == std::end(vars_)) {
return;
}
Expand All @@ -94,8 +92,7 @@ void LocalData::delete_float(std::string_view var)

void LocalData::delete_int(std::string_view var)
{
absl::string_view v{var.data(), var.size()};
auto it = vars_.find(v);
auto it = vars_.find(var);
if (it == std::end(vars_)) {
return;
}
Expand All @@ -106,8 +103,7 @@ void LocalData::delete_int(std::string_view var)

void LocalData::delete_object(std::string_view var)
{
absl::string_view v{var.data(), var.size()};
auto it = vars_.find(v);
auto it = vars_.find(var);
if (it == std::end(vars_)) {
return;
}
Expand All @@ -118,8 +114,7 @@ void LocalData::delete_object(std::string_view var)

void LocalData::delete_string(std::string_view var)
{
absl::string_view v{var.data(), var.size()};
auto it = vars_.find(v);
auto it = vars_.find(var);
if (it == std::end(vars_)) {
return;
}
Expand All @@ -130,8 +125,7 @@ void LocalData::delete_string(std::string_view var)

void LocalData::delete_location(std::string_view var)
{
absl::string_view v{var.data(), var.size()};
auto it = vars_.find(v);
auto it = vars_.find(var);
if (it == std::end(vars_)) {
return;
}
Expand All @@ -142,75 +136,65 @@ void LocalData::delete_location(std::string_view var)

float LocalData::get_float(std::string_view var) const
{
absl::string_view v(var.data(), var.size());
auto it = vars_.find(v);
auto it = vars_.find(var);
return it != vars_.end() ? it->second.float_ : 0.0f;
}

int32_t LocalData::get_int(std::string_view var) const
{
absl::string_view v(var.data(), var.size());
auto it = vars_.find(v);
auto it = vars_.find(var);
return it != vars_.end() ? it->second.integer : 0;
}

ObjectID LocalData::get_object(std::string_view var) const
{
absl::string_view v(var.data(), var.size());
auto it = vars_.find(v);
auto it = vars_.find(var);
return it != vars_.end() ? it->second.object : object_invalid;
}

std::string LocalData::get_string(std::string_view var) const
{
absl::string_view v(var.data(), var.size());
auto it = vars_.find(v);
auto it = vars_.find(var);
return it != vars_.end() ? it->second.string : std::string{};
}

Location LocalData::get_location(std::string_view var) const
{
absl::string_view v(var.data(), var.size());
auto it = vars_.find(v);
auto it = vars_.find(var);
return it != vars_.end() ? it->second.loc : Location{};
}

void LocalData::set_float(std::string_view var, float value)
{
absl::string_view v(var.data(), var.size());
auto& payload = vars_[v];
auto& payload = vars_[var];
payload.float_ = value;
payload.flags.set(LocalVarType::float_);
}

void LocalData::set_int(std::string_view var, int32_t value)
{
absl::string_view v(var.data(), var.size());
auto& payload = vars_[v];
auto& payload = vars_[var];
payload.integer = value;
payload.flags.set(LocalVarType::integer);
}

void LocalData::set_object(std::string_view var, ObjectID value)
{
absl::string_view v(var.data(), var.size());
auto& payload = vars_[v];
auto& payload = vars_[var];
payload.object = value;
payload.flags.set(LocalVarType::object);
}

void LocalData::set_string(std::string_view var, std::string_view value)
{
absl::string_view v(var.data(), var.size());
auto& payload = vars_[v];
auto& payload = vars_[var];
payload.string = std::string(value);
payload.flags.set(LocalVarType::string);
}

void LocalData::set_location(std::string_view var, Location value)
{
absl::string_view v(var.data(), var.size());
auto& payload = vars_[v];
auto& payload = vars_[var];
payload.loc = value;
payload.flags.set(LocalVarType::location);
}
Expand Down
3 changes: 1 addition & 2 deletions lib/nw/resources/NWSync.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -232,8 +232,7 @@ bool NWSync::is_loaded() const noexcept

NWSyncManifest* NWSync::get(std::string_view manifest)
{
absl::string_view v{manifest.data(), manifest.length()};
auto it = map_.find(v);
auto it = map_.find(manifest);
return it != std::end(map_) ? &it->second : nullptr;
}

Expand Down
3 changes: 1 addition & 2 deletions lib/nw/rules/Class.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -130,8 +130,7 @@ void ClassArray::clear()

Class ClassArray::from_constant(std::string_view constant) const
{
absl::string_view v{constant.data(), constant.size()};
auto it = constant_to_index.find(v);
auto it = constant_to_index.find(constant);
if (it == constant_to_index.end()) {
return Class::invalid();
} else {
Expand Down
3 changes: 1 addition & 2 deletions lib/nw/rules/rule_type.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -179,8 +179,7 @@ struct RuleTypeArray {

RuleType from_constant(std::string_view constant) const
{
absl::string_view v{constant.data(), constant.size()};
auto it = constant_to_index.find(v);
auto it = constant_to_index.find(constant);
if (it == constant_to_index.end()) {
return RuleType::invalid();
} else {
Expand Down
3 changes: 1 addition & 2 deletions lib/nw/script/Context.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -87,8 +87,7 @@ void Context::register_engine_types()

size_t Context::type_id(std::string_view type_name, bool define)
{
absl::string_view tn{type_name.data(), type_name.size()};
auto it = type_map_.find(tn);
auto it = type_map_.find(type_name);
if (it == std::end(type_map_)) {
if (!define) { return invalid_type_id; }
size_t new_id = type_array_.size();
Expand Down
19 changes: 9 additions & 10 deletions lib/nw/util/InternedString.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,36 +40,35 @@ H AbslHashValue(H h, const InternedString& str)
struct InternedStringHash {
using is_transparent = void;

size_t operator()(absl::string_view v) const
size_t operator()(std::string_view v) const
{
return absl::Hash<absl::string_view>{}(v);
return absl::Hash<std::string_view>{}(v);
}

size_t operator()(const InternedString& v) const
{
absl::string_view v2{v.view().data(), v.view().size()};
return absl::Hash<absl::string_view>{}(v2);
return absl::Hash<std::string_view>{}(v.view());
}
};

struct InternedStringEq {
using is_transparent = void;

bool operator()(const InternedString& a, absl::string_view b) const
bool operator()(const InternedString& a, std::string_view b) const
{
return std::equal(a.view().begin(), a.view().end(), b.begin(), b.end());
return a.view() == b;
}
bool operator()(absl::string_view b, const InternedString& a) const
bool operator()(std::string_view b, const InternedString& a) const
{
return std::equal(a.view().begin(), a.view().end(), b.begin(), b.end());
return a.view() == b;
}
bool operator()(const InternedString& a, const InternedString& b) const
{
return a == b;
}
bool operator()(absl::string_view b, absl::string_view a) const
bool operator()(std::string_view b, std::string_view a) const
{
return std::equal(a.begin(), a.end(), b.begin(), b.end());
return a == b;
}
};

Expand Down

0 comments on commit 6d985eb

Please sign in to comment.