mirror of
https://github.com/ultimatepp/ultimatepp.git
synced 2026-07-11 22:03:01 -06:00
cpp: Assist autocomplete speed optimized
git-svn-id: svn://ultimatepp.org/upp/trunk@8504 f0d560ea-af0d-0410-9eb7-867de7ffcac7
This commit is contained in:
parent
300b220ce9
commit
62c110d65b
4 changed files with 68 additions and 22 deletions
|
|
@ -115,8 +115,10 @@ void AssistEditor::SyncAnnotationPopup()
|
|||
pass = 2;
|
||||
break;
|
||||
}
|
||||
if(pass == 0 && cr.StartsWith("Upp::"))
|
||||
if(pass == 0 && cr.StartsWith("Upp::")) { // Patch until docs are converted
|
||||
cr = cr.Mid(5);
|
||||
cr.Replace(" Upp::", " ");
|
||||
}
|
||||
else
|
||||
break;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -10,7 +10,7 @@
|
|||
#define LLOG(x)
|
||||
#endif
|
||||
|
||||
#define LTIMING(x)
|
||||
#define LTIMING(x) // DTIMING(x)
|
||||
|
||||
class IndexSeparatorFrameCls : public CtrlFrame {
|
||||
virtual void FrameLayout(Rect& r) { r.right -= 1; }
|
||||
|
|
@ -20,11 +20,24 @@ class IndexSeparatorFrameCls : public CtrlFrame {
|
|||
virtual void FrameAddSize(Size& sz) { sz.cx += 2; }
|
||||
};
|
||||
|
||||
Value AssistEditor::AssistItemConvert::Format(const Value& q) const
|
||||
{
|
||||
int ii = q;
|
||||
if(ii >= 0 && ii < editor->assist_item_ndx.GetCount()) {
|
||||
ii = editor->assist_item_ndx[ii];
|
||||
if(ii < editor->assist_item.GetCount())
|
||||
return RawToValue(editor->assist_item[ii]);
|
||||
}
|
||||
CppItemInfo empty;
|
||||
return RawToValue(empty);
|
||||
}
|
||||
|
||||
AssistEditor::AssistEditor()
|
||||
{
|
||||
assist_convert.editor = this;
|
||||
assist.NoHeader();
|
||||
assist.NoGrid();
|
||||
assist.AddColumn().Margin(0).SetDisplay(Single<CppItemInfoDisplay>());
|
||||
assist.AddRowNumColumn().Margin(0).SetConvert(assist_convert).SetDisplay(Single<CppItemInfoDisplay>());
|
||||
assist.NoWantFocus();
|
||||
assist.WhenLeftClick = THISBACK(AssistInsert);
|
||||
type.NoHeader();
|
||||
|
|
@ -293,12 +306,11 @@ void AssistEditor::SyncAssist()
|
|||
LTIMING("SyncAssist");
|
||||
String name = ReadIdBack(GetCursor(), include_assist);
|
||||
String uname = ToUpper(name);
|
||||
assist.Clear();
|
||||
assist_item_ndx.Clear();
|
||||
int typei = type.GetCursor() - 1;
|
||||
Buffer<bool> found(assist_item.GetCount(), false);
|
||||
for(int pass = 0; pass < 2; pass++) {
|
||||
VectorMap<String, int> over;
|
||||
LTIMING("FindPass");
|
||||
for(int i = 0; i < assist_item.GetCount(); i++) {
|
||||
const CppItemInfo& m = assist_item[i];
|
||||
if(!found[i] &&
|
||||
|
|
@ -306,15 +318,15 @@ void AssistEditor::SyncAssist()
|
|||
(pass ? m.uname.StartsWith(uname) : m.name.StartsWith(name))) {
|
||||
int q = include_assist ? -1 : over.Find(m.name);
|
||||
if(q < 0 || over[q] == m.typei && m.scope.GetCount()) {
|
||||
LTIMING("Assist Add");
|
||||
found[i] = true;
|
||||
assist.Add(RawToValue(m));
|
||||
assist_item_ndx.Add(i);
|
||||
if(q < 0)
|
||||
over.Add(m.name, m.typei);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
assist.SetVirtualCount(assist_item_ndx.GetCount());
|
||||
}
|
||||
|
||||
bool AssistEditor::IncludeAssist()
|
||||
|
|
@ -375,17 +387,21 @@ bool AssistEditor::IncludeAssist()
|
|||
}
|
||||
}
|
||||
IndexSort(upper_folder, folder);
|
||||
Index<String> fnset;
|
||||
for(int i = 0; i < folder.GetCount(); i++) {
|
||||
String fn = folder[i];
|
||||
CppItemInfo& f = assist_item.GetAdd(fn);
|
||||
f.name = f.natural = fn;
|
||||
f.access = 0;
|
||||
f.kind = KIND_INCLUDEFOLDER;
|
||||
if(fnset.Find(fn) < 0) {
|
||||
fnset.Add(fn);
|
||||
CppItemInfo& f = assist_item.Add();
|
||||
f.name = f.natural = fn;
|
||||
f.access = 0;
|
||||
f.kind = KIND_INCLUDEFOLDER;
|
||||
}
|
||||
}
|
||||
IndexSort(upper_file, file);
|
||||
for(int i = 0; i < file.GetCount(); i++) {
|
||||
String fn = file[i];
|
||||
CppItemInfo& f = assist_item.Add(fn);
|
||||
CppItemInfo& f = assist_item.Add();
|
||||
f.name = f.natural = fn;
|
||||
f.access = 0;
|
||||
static Index<String> hdr(Split(".h;.hpp;.hh;.hxx", ';'));
|
||||
|
|
@ -420,6 +436,7 @@ void AssistEditor::Assist()
|
|||
q--;
|
||||
SkipSpcBack(q);
|
||||
thisback = false;
|
||||
LTIMING("Assist2");
|
||||
if(Ch(q - 1) == '(') {
|
||||
--q;
|
||||
String id = IdBack(q);
|
||||
|
|
@ -466,12 +483,14 @@ void AssistEditor::Assist()
|
|||
GatherItems("", false, in_types, true);
|
||||
}
|
||||
}
|
||||
LTIMING("Assist3");
|
||||
RemoveDuplicates();
|
||||
PopUpAssist();
|
||||
}
|
||||
|
||||
void AssistEditor::PopUpAssist(bool auto_insert)
|
||||
{
|
||||
LTIMING("PopUpAssist");
|
||||
if(assist_item.GetCount() == 0)
|
||||
return;
|
||||
int lcy = max(16, BrowserFont().Info().GetHeight());
|
||||
|
|
@ -497,6 +516,7 @@ void AssistEditor::PopUpAssist(bool auto_insert)
|
|||
return;
|
||||
// int cy = min(300, lcy * max(type.GetCount(), assist.GetCount()));
|
||||
// cy += 4;
|
||||
LTIMING("PopUpAssist2");
|
||||
int cy = VertLayoutZoom(304);
|
||||
cy += HeaderCtrl::GetStdHeight();
|
||||
assist.SetLineCy(lcy);
|
||||
|
|
@ -540,7 +560,7 @@ void AssistEditor::Complete()
|
|||
CloseAssist();
|
||||
Vector<String> id = GetFileIds();
|
||||
for(int i = 0; i < id.GetCount(); i++) {
|
||||
CppItemInfo& f = assist_item.Add(id[i]);
|
||||
CppItemInfo& f = assist_item.Add();
|
||||
f.name = id[i];
|
||||
f.natural = id[i];
|
||||
f.access = 0;
|
||||
|
|
@ -621,7 +641,16 @@ void AssistEditor::Abbr()
|
|||
void AssistEditor::AssistInsert()
|
||||
{
|
||||
if(assist.IsCursor()) {
|
||||
const CppItemInfo& f = ValueTo<CppItemInfo>(assist.Get(0));
|
||||
int ii = assist.GetCursor();
|
||||
if(ii <= 0 || ii >= assist_item_ndx.GetCount())
|
||||
return;
|
||||
ii = assist_item_ndx[ii];
|
||||
if(ii >= assist_item.GetCount()) {
|
||||
CloseAssist();
|
||||
IgnoreMouseUp();
|
||||
return;
|
||||
}
|
||||
const CppItemInfo& f = assist_item[ii];
|
||||
if(include_assist) {
|
||||
int ln = GetLine(GetCursor());
|
||||
int pos = GetPos(ln);
|
||||
|
|
|
|||
|
|
@ -125,11 +125,19 @@ struct AssistEditor : CodeEditor, Navigator {
|
|||
StaticRect navigatorpane;
|
||||
Splitter navigator_splitter;
|
||||
|
||||
struct AssistItemConvert : Convert {
|
||||
AssistEditor *editor;
|
||||
|
||||
virtual Value Format(const Value& q) const;
|
||||
}
|
||||
assist_convert;
|
||||
|
||||
Splitter popup;
|
||||
ArrayCtrl assist;
|
||||
ArrayCtrl type;
|
||||
Index<String> assist_type;
|
||||
ArrayMap<String, CppItemInfo> assist_item;
|
||||
Index<String> assist_type;
|
||||
Array<CppItemInfo> assist_item;
|
||||
Vector<int> assist_item_ndx;
|
||||
RichTextCtrl annotation_popup;
|
||||
|
||||
int assist_cursor;
|
||||
|
|
|
|||
|
|
@ -10,7 +10,7 @@
|
|||
#define LLOG(x)
|
||||
#endif
|
||||
|
||||
#define LTIMING(x)
|
||||
#define LTIMING(x) // DTIMING(x)
|
||||
|
||||
static Array<CppItem> sEmpty;
|
||||
|
||||
|
|
@ -280,7 +280,7 @@ void AssistEditor::AssistItemAdd(const String& scope, const CppItem& m, int type
|
|||
{
|
||||
if(!iscib(*m.name) || m.name.GetCount() == 0)
|
||||
return;
|
||||
CppItemInfo& f = assist_item.Add(m.name);
|
||||
CppItemInfo& f = assist_item.Add();
|
||||
f.typei = typei;
|
||||
f.scope = scope;
|
||||
(CppItem&)f = m;
|
||||
|
|
@ -288,6 +288,7 @@ void AssistEditor::AssistItemAdd(const String& scope, const CppItem& m, int type
|
|||
|
||||
void AssistEditor::GatherItems(const String& type, bool only_public, Index<String>& in_types, bool types)
|
||||
{
|
||||
LTIMING("GatherItems");
|
||||
LLOG("GatherItems " << type);
|
||||
if(in_types.Find(type) >= 0) {
|
||||
LLOG("-> recursion, exiting");
|
||||
|
|
@ -327,13 +328,13 @@ void AssistEditor::GatherItems(const String& type, bool only_public, Index<Strin
|
|||
base << im.qptype << ';';
|
||||
if((im.IsCode() || !thisback && (im.IsData() || im.IsMacro() && IsNull(type)))
|
||||
&& (!op || im.access == PUBLIC)) {
|
||||
int q = assist_item.Find(im.name);
|
||||
/* int q = assist_item.Find(im.name);
|
||||
while(q >= 0) {
|
||||
if(assist_item[q].typei != typei)
|
||||
assist_item[q].over = true;
|
||||
q = assist_item.FindNext(q);
|
||||
}
|
||||
AssistItemAdd(ntp, im, typei);
|
||||
*/ AssistItemAdd(ntp, im, typei);
|
||||
}
|
||||
}
|
||||
if(!thisback) {
|
||||
|
|
@ -353,14 +354,18 @@ void AssistEditor::GatherItems(const String& type, bool only_public, Index<Strin
|
|||
|
||||
bool OrderAssistItems(const CppItemInfo& a, const CppItemInfo& b)
|
||||
{
|
||||
return CombineCompare(a.uname, b.uname)(a.typei, b.typei)(a.qitem, b.qitem) < 0;
|
||||
return CombineCompare(a.uname, b.uname)(a.typei, b.typei)(a.qitem, b.qitem)(b.filetype, a.filetype) < 0;
|
||||
}
|
||||
|
||||
void AssistEditor::RemoveDuplicates()
|
||||
{
|
||||
LTIMING("RemoveDuplicates");
|
||||
StableSort(assist_item, OrderAssistItems);
|
||||
{ LTIMING("Sort");
|
||||
Upp::Sort(assist_item, OrderAssistItems);
|
||||
}
|
||||
Vector<int> remove;
|
||||
{
|
||||
LTIMING("Find duplicates");
|
||||
int i = 0;
|
||||
while(i < assist_item.GetCount()) { // Remove identical items
|
||||
int ii = i;
|
||||
|
|
@ -371,5 +376,7 @@ void AssistEditor::RemoveDuplicates()
|
|||
&& assist_item[ii].scope == assist_item[i].scope)
|
||||
remove.Add(i++);
|
||||
}
|
||||
}
|
||||
LTIMING("Final remove");
|
||||
assist_item.Remove(remove);
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue