Commit ac3d719a authored by Daniel Espinosa Ortiz's avatar Daniel Espinosa Ortiz

gserver: performance improvement on keywords

update keywords just after a parsing
parent 74f2e89a
......@@ -28,6 +28,8 @@ public class GVls.GServer : GLib.Object, ContainerHashable, Server
private Vala.SourceFile source = null;
private GVls.Container _vapi_dirs = new GContainer () as GVls.Container;
private weak GVls.Server _root_server = null;
private bool keywords_update = true;
private GVls.Container _keywords = null;
public GVls.Server root_server {
get { return _root_server; }
......@@ -165,6 +167,7 @@ public class GVls.GServer : GLib.Object, ContainerHashable, Server
found_using_directive (so.to_string ());
}
CodeContext.pop ();
keywords_update = true;
parsed ();
}
......@@ -183,20 +186,24 @@ public class GVls.GServer : GLib.Object, ContainerHashable, Server
}
public GVls.Container keywords {
owned get {
// Scan the document to find keywords
GScanner sc;
Container list = null;
if ("file:///@RootServer@/" in file.get_uri ()) {
sc = new GVls.GScanner.from_string (content);
} else {
sc = new GVls.GScanner.from_file (file);
}
try {
list = sc.start (this);
} catch (GLib.Error e) {
warning ("Error: %s", e.message);
if (keywords_update) {
// Scan the document to find keywords
GScanner sc;
Container list = null;
if ("file:///@RootServer@/" in file.get_uri ()) {
sc = new GVls.GScanner.from_string (content);
} else {
sc = new GVls.GScanner.from_file (file);
}
try {
list = sc.start (this);
} catch (GLib.Error e) {
warning ("Error: %s", e.message);
}
_keywords = list;
keywords_update = false;
}
return list;
return _keywords;
}
}
// Hashable Interface
......
......@@ -62,7 +62,7 @@ public class Test%d : Object {
}
srv.content = t;
var t6 = Test.timer_elapsed ();
for (int i = 0; i < 10; i++) {
for (int i = 0; i < 100; i++) {
var sd = srv.document_symbols;
sd.get_n_items ();
}
......
......@@ -59,58 +59,6 @@ class Tests {
assert_not_reached ();
}
});
Test.add_func ("/gvls/performance/document-symbols",
()=>{
var envp = GLib.Environ.get ();
string SRC_DIR = GLib.Environ.get_variable (envp, "SRC_DIR");
GLib.File file1 = GLib.File.new_for_path (SRC_DIR+"/parse.vala");
GLib.File file2 = GLib.File.new_for_path (SRC_DIR+"/namespace.vala");
assert (file1.query_exists ());
assert (file2.query_exists ());
var server = new GServer ();
var server2 = new GServer ();
var server3 = new GServer ();
try {
Test.timer_start ();
server2.parse (file1);
server.add_server (server2);
var t1 = Test.timer_elapsed ();
server3.parse (file2);
var t2 = Test.timer_elapsed ();
server.add_server (server3);
var t3 = Test.timer_elapsed ();
server.add_pkg ("gobject-2.0");
var t4 = Test.timer_elapsed ();
server.add_pkg ("gio-2.0");
var t5 = Test.timer_elapsed ();
var srv = new GServer ();
server.add_server (srv);
string t = "using GLib;";
for (int i = 0; i < 100; i++) {
t += """
public class Test%d : Object {
public string name { get; set; }
public void method (int num) {
int sti;
}
}
""".printf (i);
}
srv.content = t;
var t6 = Test.timer_elapsed ();
for (int i = 0; i < 10; i++) {
var sd = srv.document_symbols;
sd.get_n_items ();
}
var t7 = Test.timer_elapsed ();
message ("In seconts: t1: %s; t2: %s; t3: %s; t4: %s; t5: %s; t6: %s; t7: %s",
t1.to_string (), t2.to_string (), t3.to_string (),
t4.to_string (), t5.to_string (), t6.to_string (), t7.to_string ());
} catch (GLib.Error e) {
message ("Error: %s", e.message);
assert_not_reached ();
}
});
return Test.run ();
}
}
......@@ -23,7 +23,7 @@ class Tests {
{
GLib.Intl.setlocale (GLib.LocaleCategory.ALL, "");
Test.init (ref args);
Test.add_func ("/gvls/performance/document-symbols",
Test.add_func ("/gvls/performance/parsing",
()=>{
var envp = GLib.Environ.get ();
string SRC_DIR = GLib.Environ.get_variable (envp, "SRC_DIR");
......@@ -50,7 +50,7 @@ class Tests {
var srv = new GServer ();
server.add_server (srv);
string t = "using GLib;";
for (int i = 0; i < 10000; i++) {
for (int i = 0; i < 100; i++) {
t += """
public class Test%d : Object {
public string name { get; set; }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment