ctags: Add quick path for looking up too long strings in the keyword table
commitdea43baf477ab71650cdfc54fa976714def9c170
authorJiří Techet <techet@gmail.com>
Tue, 21 Mar 2023 14:46:46 +0000 (21 15:46 +0100)
committerJiří Techet <techet@gmail.com>
Tue, 21 Mar 2023 14:46:46 +0000 (21 15:46 +0100)
tree0ff3f8e922d1b6db371773ad16673402e0de6f2d
parent40d1db873b5242156732ac9e18e665ea72e76fc3
ctags: Add quick path for looking up too long strings in the keyword table

Parser code like

vString *str = vStringNew();
while (someCondition)
{
    int c = getcFromInputFile();
    vStringPut(str, c);
    if (lookupCaseKeyword (vStringValue(str), some_lang))
    {
        do_stuff();
        vStringClear(str);
    }
}

is prone to quadratic complexity because when someCondition isn't
satisfied in the parsed file, the string str grows by one in each
iteration and in each iteration lookupCaseKeyword() has to go
through strlen(str) characters to compute the hash.

Since we know the maximum length of the strings inside the keyword
hash table, we can store this value and if the queried string is
longer than this value, we can be sure it isn't present in the hash
table and return quickly without having to compute the full hash of the
string.
ctags/main/keyword.c