From 3f685ac3e131cbf89391b9e63163283e1e570a9b Mon Sep 17 00:00:00 2001 From: Brad King Date: Fri, 22 Feb 2019 08:47:45 -0500 Subject: Use shorter names in internal TARGET_PROPERTY expressions The change in commit 2f708f5d65 (Make internal TARGET_PROPERTY generator expressions more robust, 2018-09-07, v3.13.0-rc1~94^2~4) introduced globally unique names in synthesized `$` generator. We used the pattern `::T` to guarantee uniqueness. However, in projects that require many such expressions to be generated there was a measurable increase in runtime. We had included the target name in the synthesized genex only for human reference during debugging. It is not necessary. Switch to the pattern `:` to shorten the name. Also hand-roll a hex-print loop instead of using sprintf. Together these optimizations get at least some of the time back. Issue: #18964 --- Source/cmGlobalGenerator.cxx | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/Source/cmGlobalGenerator.cxx b/Source/cmGlobalGenerator.cxx index fa0ffcc..baf69f4 100644 --- a/Source/cmGlobalGenerator.cxx +++ b/Source/cmGlobalGenerator.cxx @@ -2118,17 +2118,24 @@ void cmGlobalGenerator::IndexGeneratorTarget(cmGeneratorTarget* gt) } } +static char const hexDigits[] = "0123456789abcdef"; + std::string cmGlobalGenerator::IndexGeneratorTargetUniquely( cmGeneratorTarget const* gt) { // Use the pointer value to uniquely identify the target instance. - // Use a "T" prefix to indicate that this identifier is for a target. + // Use a ":" prefix to avoid conflict with project-defined targets. // We must satisfy cmGeneratorExpression::IsValidTargetName so use no // other special characters. - char buf[64]; - sprintf(buf, "::T%p", - static_cast(gt)); // cast avoids format warning - std::string id = gt->GetName() + buf; + char buf[1 + sizeof(gt) * 2]; + char* b = buf; + *b++ = ':'; + for (size_t i = 0; i < sizeof(gt); ++i) { + unsigned char const c = reinterpret_cast(>)[i]; + *b++ = hexDigits[(c & 0xf0) >> 4]; + *b++ = hexDigits[(c & 0x0f)]; + } + std::string id(buf, sizeof(buf)); // We internally index pointers to non-const generator targets // but our callers only have pointers to const generator targets. // They will give up non-const privileges when looking up anyway. -- cgit v0.12