From fb54145b6fa767b752371384aae2d7525807f4a2 Mon Sep 17 00:00:00 2001 From: Ben Clayton Date: Wed, 2 Dec 2020 13:31:58 +0000 Subject: [PATCH] ClassID: Add some comments in ClassID::Of() Change-Id: I64df4af9cb0de05891fdcca705ecb02562262986 Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/34461 Commit-Queue: Ben Clayton Reviewed-by: dan sinclair --- src/castable.h | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/src/castable.h b/src/castable.h index 960e1b8ced..fbeb8e51c8 100644 --- a/src/castable.h +++ b/src/castable.h @@ -27,8 +27,14 @@ class ClassID { /// @returns the unique ClassID for the type T. template static ClassID Of() { - static char _; - return ClassID{reinterpret_cast(&_)}; + // Take the address of a static local variable to produce a unique + // identifier for the type T. + // We use a short name here as this method is instantiated for every + // castable class, and so we'll have a fully qualified name in the + // executable symbol table for every castable type. A shorter name produces + // a smaller executable when unstripped. + static char s; + return ClassID{reinterpret_cast(&s)}; } /// Equality operator