Always remove the return type in name shortening.

This commit is contained in:
Bartosz Taudul
2026-11-08 15:38:29 +01:00
parent ba019c3df2
commit 2f418252bc
2 changed files with 29 additions and 22 deletions
+1 -1
View File
@@ -4409,7 +4409,7 @@ Enabling the \emph{Inherit parent colors} option will cause zones that have a co
\begin{itemize}
\item \emph{Disabled} -- Shortening of zone names is not performed and names are always displayed in full (e.g.\ \texttt{bool ns::container<float>::add(const float\&)}).
\item \emph{Minimal length} -- Always reduces zone name to minimal length, even if there is space available for a longer form (e.g.\ \texttt{add()}).
\item \emph{Only normalize} -- Only performs normalization of the zone name\footnote{The normalization process removes the function \texttt{const} qualifier, some common return type declarations and all function parameters and template arguments.}, but does not remove namespaces (e.g.\ \texttt{ns::container<>::add()}).
\item \emph{Only normalize} -- Only performs normalization of the zone name\footnote{The normalization process removes the function \texttt{const} qualifier, the return type declaration and all function parameters and template arguments.}, but does not remove namespaces (e.g.\ \texttt{ns::container<>::add()}).
\item \emph{As needed} -- Name shortening steps will be performed only if there is no space to display a complete zone name, and only until the name fits available space, or shortening is no longer possible (e.g.\ \texttt{container<>::add()}).
\item \emph{As needed + normalize} -- Same as above, but zone name normalization will always be performed, even if the entire zone name fits in the space available.
\end{itemize}
+28 -21
View File
@@ -10,14 +10,6 @@
namespace tracy
{
// Short list based on GetTypes() in TracySourceTokenizer.cpp
constexpr const char* TypesList[] = {
"bool ", "char ", "double ", "float ", "int ", "long ", "short ",
"signed ", "unsigned ", "void ", "wchar_t ", "size_t ", "int8_t ",
"int16_t ", "int32_t ", "int64_t ", "intptr_t ", "uint8_t ", "uint16_t ",
"uint32_t ", "uint64_t ", "ptrdiff_t ", nullptr
};
static constexpr char OpSyms[] = "+-*/%^&|~!<>=[](){}\"";
static bool IsOperatorBracket( const char* start, const char* ptr )
@@ -98,27 +90,42 @@ const char* ShortenZoneName( ShortenName type, const char* name, ImVec2& tsz, fl
}
ptr = buf;
for(;;)
auto params = end;
while( params > buf && params[-1] != '(' ) params--;
if( params > buf )
{
auto match = TypesList;
while( *match )
auto sp = params;
for(;;)
{
auto m = *match;
auto p = ptr;
while( *m )
while( sp > buf && sp[-1] != ' ' ) sp--;
if( sp == buf ) break;
sp--;
auto word = sp;
while( word > buf && word[-1] != ' ' ) word--;
bool operatorSpace = false;
for( auto o = word; o + 8 <= sp; o++ )
{
if( *m != *p ) break;
m++;
p++;
if( ( o == word || o[-1] == ':' ) && memcmp( o, "operator", 8 ) == 0 )
{
auto t = o + 8;
while( t < sp && strchr( OpSyms, *t ) != nullptr ) t++;
if( t == sp )
{
operatorSpace = true;
break;
}
}
}
if( !*m )
if( !operatorSpace )
{
ptr = p;
auto q = buf;
while( q + 9 <= sp && memcmp( q, "operator ", 9 ) != 0 ) q++;
if( q + 9 > sp ) ptr = sp + 1;
break;
}
match++;
if( word == buf ) break;
sp = word;
}
if( !*match ) break;
}
tsz = ImGui::CalcTextSize( ptr, end );