mirror of
https://github.com/rizonesoft/Notepad3.git
synced 2026-06-14 21:09:05 +08:00
+ opt: speed optimized AutoCompletion (max. considered word length = 240)
This commit is contained in:
parent
6436e5c922
commit
eddb07c375
56
src/Edit.c
56
src/Edit.c
@ -6576,9 +6576,12 @@ void EditMarkAll(HWND hwnd, char* pszFind, int flags, DocPos rangeStart, DocPos
|
||||
// EditCompleteWord()
|
||||
// Auto-complete words (by Aleksandar Lekov)
|
||||
//
|
||||
|
||||
#define _MAX_AUTOC_WORD_LEN 240
|
||||
|
||||
typedef struct WLIST {
|
||||
char* word;
|
||||
struct WLIST* next;
|
||||
char word[_MAX_AUTOC_WORD_LEN];
|
||||
} WLIST, *PWLIST;
|
||||
|
||||
|
||||
@ -6624,7 +6627,7 @@ void EditCompleteWord(HWND hwnd, bool autoInsert)
|
||||
return;
|
||||
}
|
||||
|
||||
char pRoot[256];
|
||||
char pRoot[_MAX_AUTOC_WORD_LEN];
|
||||
DocPosCR const iRootLen = (DocPosCR)(iCurrentLinePos - iStartWordPos);
|
||||
|
||||
StringCchCopyNA(pRoot, COUNTOF(pRoot), pLine + iStartWordPos, (size_t)iRootLen);
|
||||
@ -6638,12 +6641,9 @@ void EditCompleteWord(HWND hwnd, bool autoInsert)
|
||||
DocPos iPosFind = SciCall_FindText(SCFIND_WORDSTART, &ft);
|
||||
|
||||
int iNumWords = 0;
|
||||
DocPos iWListSize = 0;
|
||||
|
||||
char pWord[256];
|
||||
WLIST wlWord = { NULL, NULL };
|
||||
wlWord.word = pWord;
|
||||
size_t iWListSize = 0;
|
||||
|
||||
PWLIST pwlWord = NULL;
|
||||
PWLIST pWLItem = NULL;
|
||||
PWLIST pListHead = NULL;
|
||||
|
||||
@ -6656,20 +6656,21 @@ void EditCompleteWord(HWND hwnd, bool autoInsert)
|
||||
while ((wordEnd < iDocLen) && StrChrIA(ALLOWED_WORD_CHARS, SciCall_GetCharAt(wordEnd))) { ++wordEnd; }
|
||||
|
||||
DocPos const wordLength = (wordEnd - iPosFind);
|
||||
if (wordLength > iRootLen) {
|
||||
if (wordLength > iRootLen)
|
||||
{
|
||||
if (!pwlWord) { pwlWord = (PWLIST)AllocMem(sizeof(WLIST), HEAP_ZERO_MEMORY); }
|
||||
if (pwlWord)
|
||||
{
|
||||
StringCchCopyNA(pwlWord->word, _MAX_AUTOC_WORD_LEN, SciCall_GetRangePointer(iPosFind, wordLength), wordLength);
|
||||
|
||||
StringCchCopyNA(wlWord.word, COUNTOF(pWord), SciCall_GetRangePointer(iPosFind, wordLength), wordLength);
|
||||
|
||||
PWLIST pPrev = NULL;
|
||||
LL_SEARCH_ORDERED(pListHead, pPrev, pWLItem, &wlWord, wordcmpi);
|
||||
if (!pWLItem) {
|
||||
PWLIST pNewWord = (PWLIST)LocalAlloc(LPTR, sizeof(WLIST));
|
||||
if (pNewWord) {
|
||||
pNewWord->word = StrDupA(pWord);
|
||||
//LL_INSERT_INORDER(pListHead, pNewWord, wordcmpi);
|
||||
LL_APPEND_ELEM(pListHead, pPrev, pNewWord);
|
||||
PWLIST pPrev = NULL;
|
||||
LL_SEARCH_ORDERED(pListHead, pPrev, pWLItem, pwlWord, wordcmp);
|
||||
if (!pWLItem) { // not found
|
||||
//LL_INSERT_INORDER(pListHead, pwlWord, wordcmpi);
|
||||
LL_APPEND_ELEM(pListHead, pPrev, pwlWord);
|
||||
++iNumWords;
|
||||
iWListSize += (wordLength + 1);
|
||||
pwlWord = NULL; // alloc new
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -6677,9 +6678,10 @@ void EditCompleteWord(HWND hwnd, bool autoInsert)
|
||||
ft.chrg.cpMin = (DocPosCR)wordEnd;
|
||||
iPosFind = SciCall_FindText(SCFIND_WORDSTART, &ft);
|
||||
}
|
||||
if (pwlWord) { FreeMem(pwlWord); pwlWord = NULL; }
|
||||
|
||||
if (iNumWords > 0) {
|
||||
|
||||
if (iNumWords > 0)
|
||||
{
|
||||
const char* const sep = " ";
|
||||
SciCall_AutoCCancel();
|
||||
SciCall_AutoCSetSeperator(sep[0]);
|
||||
@ -6690,21 +6692,21 @@ void EditCompleteWord(HWND hwnd, bool autoInsert)
|
||||
SciCall_AutoCSetFillups("\t\n\r");
|
||||
//SciCall_AutoCSetFillups(g_bAccelWordNavigation ? WhiteSpaceCharsDefault : WhiteSpaceCharsAccelerated);
|
||||
|
||||
char* pList = LocalAlloc(LPTR, iWListSize + 1);
|
||||
++iWListSize; // zero termination
|
||||
char* const pList = AllocMem(iWListSize, HEAP_ZERO_MEMORY);
|
||||
if (pList) {
|
||||
PWLIST pTmp = NULL;
|
||||
LL_FOREACH_SAFE(pListHead, pWLItem, pTmp) {
|
||||
if (pWLItem->word) {
|
||||
lstrcatA(pList, sep);
|
||||
lstrcatA(pList, pWLItem->word);
|
||||
LocalFree(pWLItem->word);
|
||||
if (pWLItem->word[0]) {
|
||||
StringCchCatA(pList, iWListSize, sep);
|
||||
StringCchCatA(pList, iWListSize, pWLItem->word);
|
||||
}
|
||||
LL_DELETE(pListHead, pWLItem);
|
||||
LocalFree(pWLItem);
|
||||
FreeMem(pWLItem);
|
||||
}
|
||||
|
||||
SciCall_AutoCShow(iRootLen, (pList + 1));
|
||||
LocalFree(pList);
|
||||
FreeMem(pList);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -2456,47 +2456,6 @@ void Float2String(float fValue, LPWSTR lpszStrg, int cchSize)
|
||||
}
|
||||
|
||||
|
||||
|
||||
//=============================================================================
|
||||
//
|
||||
// faststrcmpl()
|
||||
//
|
||||
int faststrcmpl(const char* ptr0, const char* ptr1, size_t len)
|
||||
{
|
||||
size_t fast = len / sizeof(size_t) + 1;
|
||||
size_t offset = (fast - 1) * sizeof(size_t);
|
||||
size_t cur_block = 0;
|
||||
|
||||
if (len <= sizeof(size_t)) { fast = 0; }
|
||||
|
||||
size_t* lptr0 = (size_t*)ptr0;
|
||||
size_t* lptr1 = (size_t*)ptr1;
|
||||
|
||||
while (cur_block < fast) {
|
||||
if ((lptr0[cur_block] ^ lptr1[cur_block])) {
|
||||
for (size_t pos = cur_block * sizeof(size_t); pos < len; ++pos) {
|
||||
if ((ptr0[pos] ^ ptr1[pos]) || (ptr0[pos] == 0) || (ptr1[pos] == 0)) {
|
||||
return (int)((unsigned char)ptr0[pos] - (unsigned char)ptr1[pos]);
|
||||
}
|
||||
}
|
||||
}
|
||||
++cur_block;
|
||||
}
|
||||
|
||||
while (len > offset) {
|
||||
if ((ptr0[offset] ^ ptr1[offset])) {
|
||||
return (int)((unsigned char)ptr0[offset] - (unsigned char)ptr1[offset]);
|
||||
}
|
||||
++offset;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// Drag N Drop helpers
|
||||
|
||||
@ -387,19 +387,18 @@ inline WCHAR* StrEndW(const WCHAR* pStart, size_t siz) {
|
||||
|
||||
//==== StrSafe lstrcmp(),lstrcmpi() =============================================
|
||||
|
||||
//return strcmp(a->word, b->word);
|
||||
//return _strcmpi(a->word, b->word);
|
||||
// NOTE: !!! differences in AutoCompleteList depending compare functions (CRT vs. Shlwapi)) !!!
|
||||
|
||||
//#define StringCchCompareNA(s1,l1,s2,l2) StrCmpNA((s1),(s2),min((l1),(l2)))
|
||||
#define StringCchCompareNA(s1,l1,s2,l2) StrCmpNA((s1),(s2),min((l1),(l2)))
|
||||
//#define StringCchCompareNA(s1,l1,s2,l2) strncmp((s1),(s2),min((l1),(l2)))
|
||||
#define StringCchCompareNA(s1,l1,s2,l2) faststrcmpl((s1),(s2),min((l1),(l2)))
|
||||
//#define StringCchCompareXA(s1,s2) StrCmpA((s1),(s2))
|
||||
#define StringCchCompareXA(s1,s2) StrCmpA((s1),(s2))
|
||||
//#define StringCchCompareXA(s1,s2) strcmp((s1),(s2))
|
||||
#define StringCchCompareXA(s1,s2) faststrcmp((s1),(s2))
|
||||
|
||||
#define StringCchCompareNIA(s1,l1,s2,l2) StrCmpNIA((s1),(s2),min((l1),(l2)))
|
||||
//#define StringCchCompareNIA(s1,l1,s2,l2) _strnicmp((s1),(s2),min((l1),(l2)))
|
||||
#define StringCchCompareXIA(s1,s2) StrCmpIA((s1),(s2))
|
||||
//#define StringCchCompareXIA(s1,s2) _stricmp((s1),(s2))
|
||||
|
||||
|
||||
#define StringCchCompareNW(s1,l1,s2,l2) StrCmpNW((s1),(s2),min((l1),(l2)))
|
||||
#define StringCchCompareXW(s1,s2) StrCmpW((s1),(s2))
|
||||
@ -455,9 +454,6 @@ int ReadVectorFromString(LPCWSTR wchStrg, int iVector[], int iCount, int iMin, i
|
||||
bool Char2FloatW(WCHAR* wnumber, float* fresult);
|
||||
void Float2String(float fValue, LPWSTR lpszStrg, int cchSize);
|
||||
|
||||
#define faststrcmp(p1,p2) faststrcmpl((p1),(p2), strlen(p1))
|
||||
int faststrcmpl(const char *ptr0, const char *ptr1, size_t len);
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
// including <pathcch.h> and linking against pathcch.lib
|
||||
|
||||
Loading…
Reference in New Issue
Block a user