From 1012e664efa9dfca3d7ebacb0058a2245a9bbf62 Mon Sep 17 00:00:00 2001 From: weidai Date: Fri, 9 Jun 2006 06:28:22 +0000 Subject: [PATCH] improve Integer initialization --- integer.cpp | 15 +++++++++++---- integer.h | 7 ++++++- 2 files changed, 17 insertions(+), 5 deletions(-) diff --git a/integer.cpp b/integer.cpp index 8a7767ed..cc3dfa5f 100644 --- a/integer.cpp +++ b/integer.cpp @@ -50,8 +50,6 @@ bool AssignIntToInteger(const std::type_info &valueType, void *pInteger, const v return true; } -static const char s_RunAtStartup = (g_pAssignIntToInteger = AssignIntToInteger, 0); - #ifdef SSE2_INTRINSICS_AVAILABLE template CPP_TYPENAME AllocatorBase::pointer AlignedAllocator::allocate(size_type n, const void *) @@ -1047,8 +1045,6 @@ static void SetPentiumFunctionPointers() #endif } -static const char s_RunAtStartupSetPentiumFunctionPointers = (SetPentiumFunctionPointers(), 0); - void DisableSSE2() { s_sse2Enabled = false; @@ -2726,6 +2722,17 @@ void MultiplyByPower2Mod(word *R, const word *A, size_t k, const word *M, size_t // ****************************************************************** +InitializeInteger::InitializeInteger() +{ + if (!g_pAssignIntToInteger) + { +#ifdef CRYPTOPP_X86ASM_AVAILABLE + SetPentiumFunctionPointers(); +#endif + g_pAssignIntToInteger = AssignIntToInteger; + } +} + static const unsigned int RoundupSizeTable[] = {2, 2, 2, 4, 4, 8, 8, 8, 8}; static inline size_t RoundupSize(size_t n) diff --git a/integer.h b/integer.h index 7bb051a5..a0bd85d8 100644 --- a/integer.h +++ b/integer.h @@ -67,12 +67,17 @@ NAMESPACE_BEGIN(CryptoPP) void CRYPTOPP_DLL CRYPTOPP_API DisableSSE2(); +struct InitializeInteger // used to initialize static variables +{ + InitializeInteger(); +}; + //! multiple precision integer and basic arithmetics /*! This class can represent positive and negative integers with absolute value less than (256**sizeof(word)) ** (256**sizeof(int)). \nosubgrouping */ -class CRYPTOPP_DLL Integer : public ASN1Object +class CRYPTOPP_DLL Integer : private InitializeInteger, public ASN1Object { public: //! \name ENUMS, EXCEPTIONS, and TYPEDEFS