mirror of
https://github.com/beefytech/Beef.git
synced 2025-06-14 14:24:10 +02:00
Linux compilation fix, string hash fix (dramatic speed increase)
This commit is contained in:
parent
634dd7e509
commit
71745110a5
2 changed files with 15 additions and 15 deletions
|
@ -29,7 +29,7 @@ AutoCompleteBase::~AutoCompleteBase()
|
||||||
Clear();
|
Clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
inline void UpdateEntryMatchindices(uint8* matches, AutoCompleteEntry& entry)
|
inline void UpdateEntryMatchIndices(uint8* matches, const AutoCompleteEntry& entry)
|
||||||
{
|
{
|
||||||
if (matches[0] != UINT8_MAX)
|
if (matches[0] != UINT8_MAX)
|
||||||
{
|
{
|
||||||
|
@ -55,14 +55,14 @@ inline void UpdateEntryMatchindices(uint8* matches, AutoCompleteEntry& entry)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
AutoCompleteEntry* AutoCompleteBase::AddEntry(AutoCompleteEntry& entry, const StringImpl& filter)
|
AutoCompleteEntry* AutoCompleteBase::AddEntry(const AutoCompleteEntry& entry, const StringImpl& filter)
|
||||||
{
|
{
|
||||||
uint8 matches[256];
|
uint8 matches[256];
|
||||||
|
|
||||||
if (!DoesFilterMatch(entry.mDisplay, filter.c_str(), entry.mScore, matches, 256) || (entry.mNamePrefixCount < 0))
|
if (!DoesFilterMatch(entry.mDisplay, filter.c_str(), entry.mScore, matches, 256) || (entry.mNamePrefixCount < 0))
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
UpdateEntryMatchindices(matches, entry);
|
UpdateEntryMatchIndices(matches, entry);
|
||||||
|
|
||||||
auto result = AddEntry(entry);
|
auto result = AddEntry(entry);
|
||||||
|
|
||||||
|
@ -73,14 +73,14 @@ AutoCompleteEntry* AutoCompleteBase::AddEntry(AutoCompleteEntry& entry, const St
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
AutoCompleteEntry* AutoCompleteBase::AddEntry(AutoCompleteEntry& entry, const char* filter)
|
AutoCompleteEntry* AutoCompleteBase::AddEntry(const AutoCompleteEntry& entry, const char* filter)
|
||||||
{
|
{
|
||||||
uint8 matches[256];
|
uint8 matches[256];
|
||||||
|
|
||||||
if (!DoesFilterMatch(entry.mDisplay, filter, entry.mScore, matches, 256) || (entry.mNamePrefixCount < 0))
|
if (!DoesFilterMatch(entry.mDisplay, filter, entry.mScore, matches, 256) || (entry.mNamePrefixCount < 0))
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
UpdateEntryMatchindices(matches, entry);
|
UpdateEntryMatchIndices(matches, entry);
|
||||||
|
|
||||||
auto result = AddEntry(entry);
|
auto result = AddEntry(entry);
|
||||||
|
|
||||||
|
|
|
@ -15,10 +15,10 @@ public:
|
||||||
const char* mEntryType;
|
const char* mEntryType;
|
||||||
const char* mDisplay;
|
const char* mDisplay;
|
||||||
const char* mDocumentation;
|
const char* mDocumentation;
|
||||||
int8 mNamePrefixCount;
|
mutable int8 mNamePrefixCount;
|
||||||
int mScore;
|
mutable int mScore;
|
||||||
uint8* mMatches;
|
mutable uint8* mMatches;
|
||||||
uint8 mMatchesLength;
|
mutable uint8 mMatchesLength;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
AutoCompleteEntry()
|
AutoCompleteEntry()
|
||||||
|
@ -62,7 +62,7 @@ public:
|
||||||
}
|
}
|
||||||
|
|
||||||
bool operator==(const AutoCompleteEntry& other) const
|
bool operator==(const AutoCompleteEntry& other) const
|
||||||
{
|
{
|
||||||
return strcmp(mDisplay, other.mDisplay) == 0;
|
return strcmp(mDisplay, other.mDisplay) == 0;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
@ -75,16 +75,16 @@ struct BeefHash<Beefy::AutoCompleteEntry>
|
||||||
size_t operator()(const Beefy::AutoCompleteEntry& val)
|
size_t operator()(const Beefy::AutoCompleteEntry& val)
|
||||||
{
|
{
|
||||||
intptr hash = 0;
|
intptr hash = 0;
|
||||||
const char* curPtr = val.mDisplay;
|
const char* curPtr = val.mDisplay;
|
||||||
while (true)
|
while (true)
|
||||||
{
|
{
|
||||||
char c = *(curPtr++);
|
char c = *(curPtr++);
|
||||||
if (c == 0)
|
if (c == 0)
|
||||||
break;
|
break;
|
||||||
hash = (hash ^ (intptr)c) - hash;
|
hash = ((hash ^ (intptr)c) << 5) - hash;
|
||||||
}
|
}
|
||||||
|
|
||||||
return (size_t)hash;
|
return hash;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -116,8 +116,8 @@ public:
|
||||||
int mInsertEndIdx;
|
int mInsertEndIdx;
|
||||||
|
|
||||||
bool DoesFilterMatch(const char* entry, const char* filter, int& score, uint8* matches, int maxMatches);
|
bool DoesFilterMatch(const char* entry, const char* filter, int& score, uint8* matches, int maxMatches);
|
||||||
AutoCompleteEntry* AddEntry(AutoCompleteEntry& entry, const StringImpl& filter);
|
AutoCompleteEntry* AddEntry(const AutoCompleteEntry& entry, const StringImpl& filter);
|
||||||
AutoCompleteEntry* AddEntry(AutoCompleteEntry& entry, const char* filter);
|
AutoCompleteEntry* AddEntry(const AutoCompleteEntry& entry, const char* filter);
|
||||||
AutoCompleteEntry* AddEntry(const AutoCompleteEntry& entry);
|
AutoCompleteEntry* AddEntry(const AutoCompleteEntry& entry);
|
||||||
|
|
||||||
AutoCompleteBase();
|
AutoCompleteBase();
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue