mirror of
https://github.com/encounter/dawn-cmake.git
synced 2025-06-08 07:33:33 +00:00
tint: Add TypeInfo as a field instead of a virtual
Removes the overhead of a virtual function call, at the expense of a larger object. Change-Id: I81d783d4a69b16a69143d4b313f8d90d5df88a33 Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/114080 Commit-Queue: Ben Clayton <bclayton@google.com> Kokoro: Kokoro <noreply+kokoro@google.com> Reviewed-by: Dan Sinclair <dsinclair@chromium.org> Auto-Submit: Ben Clayton <bclayton@google.com>
This commit is contained in:
parent
188ed1793a
commit
167a7da051
@ -339,7 +339,7 @@ class CastableBase {
|
|||||||
CastableBase& operator=(const CastableBase& other) = default;
|
CastableBase& operator=(const CastableBase& other) = default;
|
||||||
|
|
||||||
/// @returns the TypeInfo of the object
|
/// @returns the TypeInfo of the object
|
||||||
virtual const tint::TypeInfo& TypeInfo() const = 0;
|
inline const tint::TypeInfo& TypeInfo() const { return *type_info_; }
|
||||||
|
|
||||||
/// @returns true if this object is of, or derives from the class `TO`
|
/// @returns true if this object is of, or derives from the class `TO`
|
||||||
template <typename TO>
|
template <typename TO>
|
||||||
@ -381,6 +381,9 @@ class CastableBase {
|
|||||||
|
|
||||||
protected:
|
protected:
|
||||||
CastableBase() = default;
|
CastableBase() = default;
|
||||||
|
|
||||||
|
/// The type information for the object
|
||||||
|
const tint::TypeInfo* type_info_ = nullptr;
|
||||||
};
|
};
|
||||||
|
|
||||||
/// Castable is a helper to derive `CLASS` from `BASE`, automatically
|
/// Castable is a helper to derive `CLASS` from `BASE`, automatically
|
||||||
@ -405,9 +408,6 @@ class CastableBase {
|
|||||||
template <typename CLASS, typename BASE = CastableBase>
|
template <typename CLASS, typename BASE = CastableBase>
|
||||||
class Castable : public BASE {
|
class Castable : public BASE {
|
||||||
public:
|
public:
|
||||||
// Inherit the `BASE` class constructors.
|
|
||||||
using BASE::BASE;
|
|
||||||
|
|
||||||
/// A type alias for `CLASS` to easily access the `BASE` class members.
|
/// A type alias for `CLASS` to easily access the `BASE` class members.
|
||||||
/// Base actually aliases to the Castable instead of `BASE` so that you can
|
/// Base actually aliases to the Castable instead of `BASE` so that you can
|
||||||
/// use Base in the `CLASS` constructor.
|
/// use Base in the `CLASS` constructor.
|
||||||
@ -416,8 +416,12 @@ class Castable : public BASE {
|
|||||||
/// A type alias for `BASE`.
|
/// A type alias for `BASE`.
|
||||||
using TrueBase = BASE;
|
using TrueBase = BASE;
|
||||||
|
|
||||||
/// @returns the TypeInfo of the object
|
/// Constructor
|
||||||
const tint::TypeInfo& TypeInfo() const override { return TypeInfo::Of<CLASS>(); }
|
/// @param args the arguments to forward to the base class.
|
||||||
|
template <typename... ARGS>
|
||||||
|
inline explicit Castable(ARGS&&... args) : TrueBase(std::forward<ARGS>(args)...) {
|
||||||
|
this->type_info_ = &TypeInfo::Of<CLASS>();
|
||||||
|
}
|
||||||
|
|
||||||
/// @returns true if this object is of, or derives from the class `TO`
|
/// @returns true if this object is of, or derives from the class `TO`
|
||||||
/// @see CastFlags
|
/// @see CastFlags
|
||||||
|
Loading…
x
Reference in New Issue
Block a user