Skip to content

Commit

Permalink
Cxx: scan the cork queue instead of the symtab to fill nth fields
Browse files Browse the repository at this point in the history
Close #3634.

If an enum has so many enumerators, the original code, counting enumerators
for filling nth fields, takes a too long time.

The new code looks up the last enumerator and calculates a new nth value
by incrementing the last nth value.

Signed-off-by: Masatake YAMATO <yamato@redhat.com>
  • Loading branch information
masatake committed Feb 7, 2023
1 parent b1da453 commit 570d949
Showing 1 changed file with 24 additions and 9 deletions.
33 changes: 24 additions & 9 deletions parsers/cxx/cxx_tag.c
Original file line number Diff line number Diff line change
Expand Up @@ -275,12 +275,28 @@ void cxxTagUseTokensInRangeAsPartOfDefTags(int iCorkIndex, CXXToken * pFrom, CXX
}
}

static bool countSameKindEntry(int corkIndex,
tagEntryInfo * entry,
void * data)
static short cxxTagSearchLastNth(langType iLangType, int iScopeIndex, unsigned int uKind)
{
unsigned int *uKind = data;
return (entry->kindIndex == *uKind);
for (size_t uCount = countEntryInCorkQueue (); uCount > (CORK_NIL + 1); uCount--)
{
int iCorkIndex = (int)(uCount - 1);
tagEntryInfo *pTag = getEntryInCorkQueue(iCorkIndex);
if (iCorkIndex == iScopeIndex)
return 0;
else if (pTag->extensionFields.scopeIndex == iScopeIndex
&& pTag->langType == iLangType
&& pTag->kindIndex == uKind)
{
return pTag->extensionFields.nth + (
/* Over-wrapped; if the value is too large for sizeof(nth),
* Don't increment more. */
((short)(pTag->extensionFields.nth + 1) > 0)
? 1
: 0
);
}
}
return NO_NTH_FIELD;
}

tagEntryInfo * cxxTagBegin(unsigned int uKind,CXXToken * pToken)
Expand Down Expand Up @@ -315,10 +331,9 @@ tagEntryInfo * cxxTagBegin(unsigned int uKind,CXXToken * pToken)
{
if (uKind == CXXTagKindMEMBER || uKind == CXXTagKindENUMERATOR
|| uKind == CXXTagKindPARAMETER || uKind == CXXTagCPPKindTEMPLATEPARAM)
g_oCXXTag.extensionFields.nth =
(short) countEntriesInScope(g_oCXXTag.extensionFields.scopeIndex,
true,
countSameKindEntry, &uKind);
g_oCXXTag.extensionFields.nth = cxxTagSearchLastNth(g_oCXXTag.langType,
g_oCXXTag.extensionFields.scopeIndex,
uKind);
}
}

Expand Down

0 comments on commit 570d949

Please sign in to comment.