2021-03-05 12:09:31 +00:00
|
|
|
diff --git a/components/cast_channel/enum_table.h b/components/cast_channel/enum_table.h
|
2021-09-16 18:37:52 +00:00
|
|
|
index a63ae86..83ada65 100644
|
2021-03-05 12:09:31 +00:00
|
|
|
--- a/components/cast_channel/enum_table.h
|
|
|
|
|
+++ b/components/cast_channel/enum_table.h
|
2021-09-16 18:37:52 +00:00
|
|
|
@@ -8,6 +8,7 @@
|
|
|
|
|
#include <cstdint>
|
|
|
|
|
#include <cstring>
|
|
|
|
|
#include <ostream>
|
|
|
|
|
+#include <vector>
|
|
|
|
|
|
|
|
|
|
#include "base/check_op.h"
|
|
|
|
|
#include "base/macros.h"
|
|
|
|
|
@@ -213,7 +214,7 @@ class
|
2021-03-05 12:09:31 +00:00
|
|
|
|
|
|
|
|
template <typename E>
|
|
|
|
|
friend class EnumTable;
|
|
|
|
|
- DISALLOW_COPY_AND_ASSIGN(GenericEnumTableEntry);
|
|
|
|
|
+ DISALLOW_ASSIGN(GenericEnumTableEntry);
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
// Yes, these constructors really needs to be inlined. Even though they look
|
2021-09-16 18:37:52 +00:00
|
|
|
@@ -251,8 +252,7 @@ class EnumTable {
|
2021-03-05 12:09:31 +00:00
|
|
|
// Constructor for regular entries.
|
|
|
|
|
constexpr Entry(E value, base::StringPiece str)
|
|
|
|
|
: GenericEnumTableEntry(static_cast<int32_t>(value), str) {}
|
|
|
|
|
-
|
|
|
|
|
- DISALLOW_COPY_AND_ASSIGN(Entry);
|
|
|
|
|
+ DISALLOW_ASSIGN(Entry);
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
static_assert(sizeof(E) <= sizeof(int32_t),
|
2021-09-16 18:37:52 +00:00
|
|
|
@@ -307,15 +307,14 @@ class EnumTable {
|
2021-03-05 12:09:31 +00:00
|
|
|
if (is_sorted_) {
|
|
|
|
|
const std::size_t index = static_cast<std::size_t>(value);
|
|
|
|
|
if (ANALYZER_ASSUME_TRUE(index < data_.size())) {
|
|
|
|
|
- const auto& entry = data_.begin()[index];
|
|
|
|
|
+ const auto& entry = data_[index];
|
|
|
|
|
if (ANALYZER_ASSUME_TRUE(entry.has_str()))
|
|
|
|
|
return entry.str();
|
|
|
|
|
}
|
2021-08-01 11:30:34 +00:00
|
|
|
return absl::nullopt;
|
2021-03-05 12:09:31 +00:00
|
|
|
}
|
|
|
|
|
return GenericEnumTableEntry::FindByValue(
|
|
|
|
|
- reinterpret_cast<const GenericEnumTableEntry*>(data_.begin()),
|
|
|
|
|
- data_.size(), static_cast<int32_t>(value));
|
|
|
|
|
+ &data_[0], data_.size(), static_cast<int32_t>(value));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// This overload of GetString is designed for cases where the argument is a
|
2021-09-16 18:37:52 +00:00
|
|
|
@@ -343,8 +342,7 @@ class EnumTable {
|
2021-03-05 12:09:31 +00:00
|
|
|
// enum value directly.
|
2021-08-01 11:30:34 +00:00
|
|
|
absl::optional<E> GetEnum(base::StringPiece str) const {
|
2021-03-05 12:09:31 +00:00
|
|
|
auto* entry = GenericEnumTableEntry::FindByString(
|
|
|
|
|
- reinterpret_cast<const GenericEnumTableEntry*>(data_.begin()),
|
|
|
|
|
- data_.size(), str);
|
|
|
|
|
+ &data_[0], data_.size(), str);
|
2021-08-01 11:30:34 +00:00
|
|
|
return entry ? static_cast<E>(entry->value) : absl::optional<E>();
|
2021-03-05 12:09:31 +00:00
|
|
|
}
|
|
|
|
|
|
2021-09-16 18:37:52 +00:00
|
|
|
@@ -359,7 +357,7 @@ class EnumTable {
|
2021-03-05 12:09:31 +00:00
|
|
|
// Align the data on a cache line boundary.
|
|
|
|
|
alignas(64)
|
|
|
|
|
#endif
|
|
|
|
|
- std::initializer_list<Entry> data_;
|
|
|
|
|
+ const std::vector<Entry> data_;
|
|
|
|
|
bool is_sorted_;
|
|
|
|
|
|
|
|
|
|
constexpr EnumTable(std::initializer_list<Entry> data, bool is_sorted)
|
2021-09-16 18:37:52 +00:00
|
|
|
@@ -371,8 +369,8 @@ class EnumTable {
|
2021-03-05 12:09:31 +00:00
|
|
|
|
|
|
|
|
for (std::size_t i = 0; i < data.size(); i++) {
|
|
|
|
|
for (std::size_t j = i + 1; j < data.size(); j++) {
|
|
|
|
|
- const Entry& ei = data.begin()[i];
|
|
|
|
|
- const Entry& ej = data.begin()[j];
|
|
|
|
|
+ const Entry& ei = data[i];
|
|
|
|
|
+ const Entry& ej = data[j];
|
|
|
|
|
DCHECK(ei.value != ej.value)
|
|
|
|
|
<< "Found duplicate enum values at indices " << i << " and " << j;
|
|
|
|
|
DCHECK(!(ei.has_str() && ej.has_str() && ei.str() == ej.str()))
|