Commit e830e07
Speed optimizations and benchmarks
Changed files (4)
modifiedbirdfont-test/TestRunner.valamodifiedlibbirdfont/EditPoint.valamodifiedlibbirdfont/EditPointHandle.valamodifiedlibbirdfont/Path.vala
Diff
@@ -48,8 +48,48 @@ public class TestRunner : NativeWindow, GLib.Object { } static void speed_test () {+ Test test_object = new Test.time ("GObject");+ + for (uint i = 0; i < 3000 * 300; i++) {+ GLib.Object o = new GLib.Object ();+ }+ + test_object.print ();++ Test test_ref = new Test.time ("GObject ref");+ + for (uint i = 0; i < 3000 * 300; i++) {+ GLib.Object o = new GLib.Object ();+ + for (int j = 0; j < 7; j++) {+ o.ref ();+ }+ + for (int j = 0; j < 7; j++) {+ o.unref ();+ }+ }+ + test_ref.print ();+ + Test test_edit_point = new Test.time ("EditPoint creation");+ + for (uint i = 0; i < 3000 * 300; i++) {+ EditPoint ep = new EditPoint ();+ }+ + test_edit_point.print ();+ Test test_path = new Test.time ("Simple path creation"); + for (uint i = 0; i < 3000 * 300; i++) {+ Path p = new Path ();+ }+ + test_path.print ();++ Test test_points = new Test.time ("Simple path with points");+ for (int i = 0; i < 3000; i++) { Path p = new Path (); for (int j = 0; j < 300; j++) {@@ -57,7 +97,7 @@ public class TestRunner : NativeWindow, GLib.Object { } } - test_path.print ();+ test_points.print (); Test test_cairo = new Test.time ("Simple Cairo"); @@ -68,7 +108,7 @@ public class TestRunner : NativeWindow, GLib.Object { s = Screen.create_background_surface (1000, 1000); c = new Context (s); - for (int j = 0; j < 30; j++) {+ for (int j = 0; j < 300; j++) { c.save (); c.rectangle (100, 100, 100, 100); c.fill ();@@ -76,7 +116,62 @@ public class TestRunner : NativeWindow, GLib.Object { } } - test_cairo.print (); + test_cairo.print ();+++ Test test_toolbox = new Test.time ("Toolbox");+ + for (int i = 0; i < 30; i++) {+ ImageSurface s;+ Context c;+ + s = Screen.create_background_surface (1000, 1000);+ c = new Context (s);+ MainWindow.get_toolbox ().draw (300, 500, c); + }+ + test_toolbox.print ();++ Test test_tool_drawing = new Test.time ("Draw Tool");+ + for (int i = 0; i < 30; i++) {+ ImageSurface s;+ Context c;+ Tool tool;+ + tool = new Tool ();+ s = Screen.create_background_surface (100, 100);+ c = new Context (s);+ MainWindow.get_toolbox ().draw (300, 500, c); + }+ + test_tool_drawing.print ();+ + Test test_tool = new Test.time ("Create Tool");+ + for (int i = 0; i < 30; i++) {+ Tool tool;+ tool = new Tool ();+ tool.set_tool_visibility (true);+ }+ + test_tool.print ();+ ++ Test test_text = new Test.time ("Text");+ + for (int i = 0; i < 30; i++) {+ ImageSurface s;+ Context c;+ + s = Screen.create_background_surface (100, 100);+ c = new Context (s);+ + Text text = new Text ("This is a test.");+ text.draw_at_top (c, 0, 0);+ }+ + test_text.print (); } public void file_chooser (string title, FileChooser file_chooser_callback, uint flags) {@@ -38,28 +38,28 @@ public class EditPoint : GLib.Object { public unowned EditPoint? prev = null; public unowned EditPoint? next = null; - public static uint NONE = 0;- public static uint ACTIVE = 1;- public static uint SELECTED = 1 << 1;- public static uint DELETED = 1 << 2;- public static uint TIE = 1 << 3;- public static uint REFLECTIVE = 1 << 4;+ public static const uint NONE = 0;+ public static const uint ACTIVE = 1;+ public static const uint SELECTED = 1 << 1;+ public static const uint DELETED_POINT = 1 << 2;+ public static const uint TIE = 1 << 3;+ public static const uint REFLECTIVE = 1 << 4; - public static uint INTERSECTION = 1 << 5;- public static uint NEW_CORNER = 1 << 6;- public static uint STROKE_OFFSET = 1 << 7;- public static uint COUNTER_TO_OUTLINE = 1 << 8;- public static uint COPIED = 1 << 9;- public static uint REMOVE_PART = 1 << 10;- public static uint OVERLAY = 1 << 11;- public static uint CURVE = 1 << 12;- public static uint CURVE_KEEP = 1 << 13;- public static uint SEGMENT_END = 1 << 14;- public static uint SPLIT_POINT = 1 << 15;- public static uint SELF_INTERSECTION = 1 << 16;- public static uint COPIED_SELF_INTERSECTION = 1 << 17;+ public static const uint INTERSECTION = 1 << 5;+ public static const uint NEW_CORNER = 1 << 6;+ public static const uint STROKE_OFFSET = 1 << 7;+ public static const uint COUNTER_TO_OUTLINE = 1 << 8;+ public static const uint COPIED = 1 << 9;+ public static const uint REMOVE_PART = 1 << 10;+ public static const uint OVERLAY = 1 << 11;+ public static const uint CURVE = 1 << 12;+ public static const uint CURVE_KEEP = 1 << 13;+ public static const uint SEGMENT_END = 1 << 14;+ public static const uint SPLIT_POINT = 1 << 15;+ public static const uint SELF_INTERSECTION = 1 << 16;+ public static const uint COPIED_SELF_INTERSECTION = 1 << 17; - public static uint ALL = 0xFFFFFF;+ public static const uint ALL = 0xFFFFFF; public uint flags = NONE; @@ -93,14 +93,14 @@ public class EditPoint : GLib.Object { public bool deleted { get {- return (flags & DELETED) > 0;+ return (flags & DELETED_POINT) > 0; } set { if (value) {- flags |= DELETED;+ flags |= DELETED_POINT; } else {- flags &= uint.MAX ^ DELETED;+ flags &= uint.MAX ^ DELETED_POINT; } } }@@ -166,16 +166,20 @@ public class EditPoint : GLib.Object { } public Color? color = null;- - static int n_points = 0;- + public EditPoint (double nx = 0, double ny = 0, PointType nt = PointType.NONE) { x = nx; y = ny; type = nt;- active_point = false;- - set_active (true);+ right_handle = new EditPointHandle (this, 0, 7);+ left_handle = new EditPointHandle (this, PI, 7); + }+ + public EditPoint.full (double nx = 0, double ny = 0, PointType nt = PointType.NONE) {+ x = nx;+ y = ny;+ type = nt;+ active_point = true; if (nt == PointType.FLOATING) { active_point = false;@@ -188,13 +192,7 @@ public class EditPoint : GLib.Object { warning (@"Invalid point at ($nx,$ny)."); x = 0; y = 0;- }- - n_points++;- }-- ~EditPoint () {- n_points--;+ } } public bool is_valid () {@@ -78,8 +78,6 @@ public class EditPointHandle : GLib.Object { } } - static int n_handles = 0;- public EditPointHandle.empty() { this.parent = none; this.angle = 0;@@ -87,8 +85,6 @@ public class EditPointHandle : GLib.Object { this.type = PointType.NONE; this.active = false; this.selected = false;- - n_handles++; } public EditPointHandle (EditPoint parent, double angle, double length) {@@ -98,12 +94,6 @@ public class EditPointHandle : GLib.Object { this.type = PointType.LINE_CUBIC; this.active = false; this.selected = false;- - n_handles++;- }-- ~EditPointHandle () {- n_handles--; } public EditPointHandle copy () {@@ -964,11 +964,24 @@ public class Path : GLib.Object { } public EditPoint add_point (EditPoint p) {- if (points.size > 0) {- return add_point_after (p, points.get (points.size - 1));+ int prev_index;+ EditPoint previous_point;+ + if (points.size == 0) {+ points.add (p);+ p.prev = points.get (0).get_link_item ();+ p.next = points.get (0).get_link_item ();+ } else {+ previous_point = points.get (points.size - 1);+ points.add (p);+ p.prev = (!) previous_point;+ p.next = null;+ points.add (p); } - return add_point_after (p, null);+ last_point = p;+ + return p; } /** Insert a new point after @param previous_point and return a reference