vector reserve the size to reduce reallocation

This commit is contained in:
Xiao YiFang 2022-08-12 20:17:25 +08:00
parent 39a7c85303
commit 9a708bfd81

View file

@ -1117,6 +1117,11 @@ void IndexedWords::addWord( wstring const & word, uint32_t articleOffset, unsign
if( ( i->second.size() < 1024 ) || ( nextChar == wordBegin ) ) // Don't overpopulate chains with middle matches
{
// reduce the vector reallocation.
if( i->second.size() * 1.0 / i->second.capacity() > 0.75 )
{
i->second.reserve( i->second.capacity() * 2 );
}
string utfWord = Utf8::encode( wstring( nextChar, wordSize - ( nextChar - wordBegin ) ) );
string utfPrefix = Utf8::encode( wstring( wordBegin, nextChar - wordBegin ) );