forked from mirrors/gecko-dev
Bug 1728769 - Use std::underlying_type_t for profile buffer enum types r=canaltinova
This patch replaces "custom" underlying type definitions with definitions gleaned using the std::underlying_type mechanism. This allows us to directly set the underlying type for the enums without having to name it, and reduces the number of semantically identical names in the profile buffer code. Differential Revision: https://phabricator.services.mozilla.com/D174260
This commit is contained in:
parent
d3cdd3192f
commit
82c01addf1
4 changed files with 11 additions and 9 deletions
|
|
@ -19,13 +19,15 @@
|
||||||
#include "mozilla/Vector.h"
|
#include "mozilla/Vector.h"
|
||||||
|
|
||||||
#include <string>
|
#include <string>
|
||||||
|
#include <type_traits>
|
||||||
|
|
||||||
namespace mozilla {
|
namespace mozilla {
|
||||||
namespace baseprofiler {
|
namespace baseprofiler {
|
||||||
|
|
||||||
class ProfileBufferEntry {
|
class ProfileBufferEntry {
|
||||||
public:
|
public:
|
||||||
using KindUnderlyingType = ::mozilla::ProfileBufferEntryKindUnderlyingType;
|
using KindUnderlyingType =
|
||||||
|
std::underlying_type_t<::mozilla::ProfileBufferEntryKind>;
|
||||||
using Kind = ::mozilla::ProfileBufferEntryKind;
|
using Kind = ::mozilla::ProfileBufferEntryKind;
|
||||||
|
|
||||||
ProfileBufferEntry();
|
ProfileBufferEntry();
|
||||||
|
|
|
||||||
|
|
@ -23,6 +23,7 @@
|
||||||
|
|
||||||
#include <limits>
|
#include <limits>
|
||||||
#include <tuple>
|
#include <tuple>
|
||||||
|
#include <type_traits>
|
||||||
|
|
||||||
namespace mozilla::baseprofiler {
|
namespace mozilla::baseprofiler {
|
||||||
// Implemented in platform.cpp
|
// Implemented in platform.cpp
|
||||||
|
|
@ -407,8 +408,8 @@ void DeserializeAfterKindAndStream(
|
||||||
}
|
}
|
||||||
|
|
||||||
auto payloadType = static_cast<mozilla::MarkerPayloadType>(
|
auto payloadType = static_cast<mozilla::MarkerPayloadType>(
|
||||||
aEntryReader
|
aEntryReader.ReadObject<
|
||||||
.ReadObject<mozilla::MarkerPayloadTypeUnderlyingType>());
|
std::underlying_type_t<mozilla::MarkerPayloadType>>());
|
||||||
|
|
||||||
// Stream the payload, including the type.
|
// Stream the payload, including the type.
|
||||||
switch (payloadType) {
|
switch (payloadType) {
|
||||||
|
|
|
||||||
|
|
@ -60,9 +60,7 @@ static constexpr size_t ProfileBufferEntryNumChars = 8;
|
||||||
// more efficient kinds of entries (e.g., stack frames could be stored in one
|
// more efficient kinds of entries (e.g., stack frames could be stored in one
|
||||||
// bigger entry, instead of multiple `ProfileBufferEntry`s); then we could
|
// bigger entry, instead of multiple `ProfileBufferEntry`s); then we could
|
||||||
// discard `ProfileBufferEntry` and move this enum to a more appropriate spot.
|
// discard `ProfileBufferEntry` and move this enum to a more appropriate spot.
|
||||||
using ProfileBufferEntryKindUnderlyingType = uint8_t;
|
enum class ProfileBufferEntryKind : uint8_t {
|
||||||
|
|
||||||
enum class ProfileBufferEntryKind : ProfileBufferEntryKindUnderlyingType {
|
|
||||||
INVALID = 0,
|
INVALID = 0,
|
||||||
#define KIND(KIND, TYPE, SIZE) KIND,
|
#define KIND(KIND, TYPE, SIZE) KIND,
|
||||||
FOR_EACH_PROFILE_BUFFER_ENTRY_KIND(KIND)
|
FOR_EACH_PROFILE_BUFFER_ENTRY_KIND(KIND)
|
||||||
|
|
@ -97,8 +95,7 @@ enum class ProfileBufferEntryKind : ProfileBufferEntryKindUnderlyingType {
|
||||||
MODERN_LIMIT
|
MODERN_LIMIT
|
||||||
};
|
};
|
||||||
|
|
||||||
using MarkerPayloadTypeUnderlyingType = uint8_t;
|
enum class MarkerPayloadType : uint8_t {
|
||||||
enum class MarkerPayloadType : MarkerPayloadTypeUnderlyingType {
|
|
||||||
Cpp,
|
Cpp,
|
||||||
Rust,
|
Rust,
|
||||||
};
|
};
|
||||||
|
|
|
||||||
|
|
@ -11,6 +11,7 @@
|
||||||
#include <cstdlib>
|
#include <cstdlib>
|
||||||
#include <functional>
|
#include <functional>
|
||||||
#include <utility>
|
#include <utility>
|
||||||
|
#include <type_traits>
|
||||||
#include "gtest/MozGtestFriend.h"
|
#include "gtest/MozGtestFriend.h"
|
||||||
#include "js/ProfilingCategory.h"
|
#include "js/ProfilingCategory.h"
|
||||||
#include "mozilla/Attributes.h"
|
#include "mozilla/Attributes.h"
|
||||||
|
|
@ -30,7 +31,8 @@ struct JSContext;
|
||||||
|
|
||||||
class ProfileBufferEntry {
|
class ProfileBufferEntry {
|
||||||
public:
|
public:
|
||||||
using KindUnderlyingType = mozilla::ProfileBufferEntryKindUnderlyingType;
|
using KindUnderlyingType =
|
||||||
|
std::underlying_type_t<::mozilla::ProfileBufferEntryKind>;
|
||||||
using Kind = mozilla::ProfileBufferEntryKind;
|
using Kind = mozilla::ProfileBufferEntryKind;
|
||||||
|
|
||||||
ProfileBufferEntry();
|
ProfileBufferEntry();
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue