From: Matthew Fernandez Date: Thu, 22 Apr 2021 02:48:13 +0000 (-0700) Subject: compute tclhandleEntryAlignment at compile time X-Git-Tag: 2.47.2~39^2~2 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=d0963b7a27ac7a13815af78c4233414db0872a2e;p=graphviz compute tclhandleEntryAlignment at compile time There is no need to defer this to runtime. Making this a compile-time constant allows the compiler to constant-fold computations involving it, producing more efficient code. Note, this is not really even the correct notion of platform alignment. The alignment of a type is not guaranteed to be the same as its size. Nevertheless, we leave this alone for now. --- diff --git a/tclpkg/tclhandle/tclhandle.c b/tclpkg/tclhandle/tclhandle.c index 8e9866592..f0e7c7115 100644 --- a/tclpkg/tclhandle/tclhandle.c +++ b/tclpkg/tclhandle/tclhandle.c @@ -42,10 +42,12 @@ #include /* - * Variable set to contain the alignment factor (in bytes) for this machine. - * It is set on the first table initialization. + * Alignment factor (in bytes) for this machine. */ -static uint64_t tclhandleEntryAlignment = 0; +enum { tclhandleEntryAlignment = + sizeof(void*) > sizeof(uint64_t) + ? (sizeof(double) > sizeof(void*) ? sizeof(double) : sizeof(void*)) + : (sizeof(double) > sizeof(uint64_t) ? sizeof(double) : sizeof(uint64_t)) }; /*============================================================================= * tclhandleLinkInNewEntries -- @@ -159,18 +161,6 @@ tblHeader_pt tclhandleInit(char *prefix, uint64_t entrySize, { tblHeader_pt tblHdrPtr; - /* - * It its not been calculated yet, determine the entry alignment required - * for this machine. - */ - if (tclhandleEntryAlignment == 0) { - tclhandleEntryAlignment = sizeof(void *); - if (sizeof(uint64_t) > tclhandleEntryAlignment) - tclhandleEntryAlignment = sizeof(uint64_t); - if (sizeof(double) > tclhandleEntryAlignment) - tclhandleEntryAlignment = sizeof(double); - } - /* * Set up the table entry. */