Clone in a terminal:
Commit ecd11cd
Johan Mattsson - 2015-10-16T08:47:11+00:00
ecd11cda43af653b60b9d7b5a73e7790b0c0a5e2johan.mattsson.m@gmail.com

Speed optimizations This commit removes old optimizations as well.

Changed files (5)

Diff

diff --git a/birdfont-test/TestRunner.vala b/birdfont-test/TestRunner.valaindex 9baa8bd..b5c69b5 100644--- a/birdfont-test/TestRunner.vala+++ b/birdfont-test/TestRunner.vala@@ -89,7 +89,7 @@ public class TestRunner : NativeWindow, GLib.Object  { 		Test test_path = new Test.time ("Simple path creation"); 		 		for (uint i = 0; i < 3000; i++) {-			for (uint j = 0; j < 3000; j++) {+			for (uint j = 0; j < 300; j++) { 				Path p = new Path (); 			} 		}@@ -109,7 +109,7 @@ public class TestRunner : NativeWindow, GLib.Object  { 		 		Test test_cairo = new Test.time ("Simple Cairo"); 		-		for (int i = 0; i < 3000; i++) {+		for (int i = 0; i < 300; i++) { 			ImageSurface s; 			Context c; 			@@ -129,7 +129,7 @@ public class TestRunner : NativeWindow, GLib.Object  {  		Test test_toolbox = new Test.time ("Toolbox"); 		-		for (int i = 0; i < 30; i++) {+		for (int i = 0; i < 3000; i++) { 			ImageSurface s; 			Context c; 			@@ -142,7 +142,7 @@ public class TestRunner : NativeWindow, GLib.Object  {  		Test test_tool_drawing = new Test.time ("Draw Tool"); 		-		for (int i = 0; i < 30; i++) {+		for (int i = 0; i < 3000; i++) { 			ImageSurface s; 			Context c; 			Tool tool;@@ -157,7 +157,7 @@ public class TestRunner : NativeWindow, GLib.Object  { 		 		Test test_tool = new Test.time ("Create Tool"); 		-		for (int i = 0; i < 30; i++) {+		for (int i = 0; i < 3000; i++) { 			Tool tool; 			tool = new Tool (); 			tool.set_tool_visibility (true);diff --git a/libbirdfont/Path.vala b/libbirdfont/Path.valaindex 2e58509..eed5b7e 100644--- a/libbirdfont/Path.vala+++ b/libbirdfont/Path.vala@@ -956,11 +956,8 @@ public class Path : GLib.Object { 	} 	 	public EditPoint add (double x, double y) {-		if (points.size > 0) {-			return add_after (x, y, points.get (points.size - 1));-		}-		-		return add_after (x, y, null);+		EditPoint ep = new EditPoint (x, y);+		return add_point (ep); 	}  	public EditPoint add_point (EditPoint p) {@@ -981,14 +978,6 @@ public class Path : GLib.Object { 		 		return p; 	}--	/** Insert a new point after @param previous_point and return a reference -	 * to the new item in list.-	 */-	public EditPoint add_after (double x, double y, EditPoint? previous_point) {-		EditPoint p = new EditPoint (x, y, PointType.NONE);	-		return add_point_after (p, previous_point);-	} 	 	/** @return a list item pointing to the new point */ 	public EditPoint add_point_after (EditPoint p, EditPoint? previous_point) {@@ -2454,9 +2443,16 @@ public class Path : GLib.Object { 			return; 		} 		-		print(@"Create full stroke for $(points.size) points.\n"); 		StrokeTask task = new StrokeTask (this);-		MainWindow.native_window.run_non_blocking_background_thread (task);+		+		// Create idle task in order ignore repeted calls to this method+		// during one main loop iteration.+		IdleSource idle = new IdleSource ();+		idle.set_callback (() => {			+			MainWindow.native_window.run_non_blocking_background_thread (task);+			return false;+		});+		idle.attach (null); 		 		stop_stroke_creator (); 		stroke_creator = task;@@ -2487,9 +2483,7 @@ public class Path : GLib.Object { 		} 		 		StrokeTool s = new StrokeTool ();-		Test t = new Test.time ("fast stroke"); 		fast_stroke = s.get_stroke_fast (this, stroke);-		t.print(); 		 		return (!) fast_stroke; 	}diff --git a/libbirdfont/PenTool.vala b/libbirdfont/PenTool.valaindex 9c78ae6..e9f9efb 100644--- a/libbirdfont/PenTool.vala+++ b/libbirdfont/PenTool.vala@@ -149,8 +149,8 @@ public class PenTool : Tool {  		release_action.connect ((self, b, ix, iy) => { 			double x, y;-			Glyph g;-			+			Glyph g;			+	 			g = MainWindow.get_current_glyph (); 			x = Glyph.path_coordinate_x (ix); 			y = Glyph.path_coordinate_y (iy);@@ -176,8 +176,7 @@ public class PenTool : Tool {  			point_selection_image = false; 			BirdFont.get_current_font ().touch ();-			reset_stroke ();-			+ 			foreach (Path p in g.get_visible_paths ()) { 				if (p.is_open () && p.points.size > 0) { 					p.get_first_point ().set_tie_handle (false);diff --git a/libbirdfont/StrokeTask.vala b/libbirdfont/StrokeTask.valaindex 2a559cc..3b7531a 100644--- a/libbirdfont/StrokeTask.vala+++ b/libbirdfont/StrokeTask.vala@@ -37,10 +37,7 @@ public class StrokeTask : Task { 		 		w = background_path.stroke; 		-		Test t = new Test.time ("full stroke"); 		stroke = tool.get_stroke (background_path, w);-		t.print ();-		print(@"Cancelled: $(is_cancelled ())\n"); 		 		IdleSource idle = new IdleSource ();  		idle.set_callback (() => {	diff --git a/libbirdfont/StrokeTool.vala b/libbirdfont/StrokeTool.valaindex 8749579..c2681af 100644--- a/libbirdfont/StrokeTool.vala+++ b/libbirdfont/StrokeTool.vala@@ -85,7 +85,7 @@ public class StrokeTool : GLib.Object { 		 		stroke = path.copy (); 		stroke.remove_points_on_points (0.1);-		o = s.create_stroke (stroke, thickness, false); // set to true for faster stroke+		o = s.create_stroke (stroke, thickness); 				 		return o; 	}@@ -94,9 +94,13 @@ public class StrokeTool : GLib.Object { 		PathList o, m; 		Path stroke; 		+		if (task.is_cancelled ()) {+			return new PathList ();+		}+		 		stroke = path.copy (); 		stroke.remove_points_on_points (0.1);-		o = create_stroke (stroke, thickness, false);+		o = create_stroke (stroke, thickness); 		o = get_all_parts (o); 		o = remove_intersection_paths (o); 		o = merge (o);@@ -112,8 +116,7 @@ public class StrokeTool : GLib.Object { 	void reset_flags (PathList o) { 		foreach (Path p in o.paths) { 			foreach (EditPoint ep in p.points) {-				ep.flags &= uint.MAX ^ -					(EditPoint.INTERSECTION +				ep.flags &= ~(EditPoint.INTERSECTION  						| EditPoint.COPIED  						| EditPoint.NEW_CORNER  						| EditPoint.SELF_INTERSECTION);@@ -2784,8 +2787,7 @@ public class StrokeTool : GLib.Object { 		return sum > 0; 	}	 -	public PathList create_stroke (Path original_path,-		double thickness, bool fast) {+	public PathList create_stroke (Path original_path, double thickness) { 			 		PathList pl; 		EditPoint p1, p2, p3;@@ -2834,7 +2836,7 @@ public class StrokeTool : GLib.Object { 		corner1 = new EditPoint (); 		corner1_inside = new EditPoint (); 				-		if (path.is_open () || fast) {+		if (path.is_open ()) { 			p1 = path.points.get (0); 			p2 = path.points.get (1 % path.points.size); 			@@ -2852,17 +2854,16 @@ public class StrokeTool : GLib.Object { 		}  		min_increment = 0.02; // 0.013-		-		Test t1 = new Test.time ("generate");+ 		for (i = 0; i < size; i++) { 			p1 = path.points.get (i % path.points.size); 			p2 = path.points.get ((i + 1) % path.points.size); 			p3 = path.points.get ((i + 2) % path.points.size); -			if (task.is_cancelled ()) {+			if (unlikely (task.is_cancelled ())) { 				return new PathList (); 			}-					+ 			tolerance = 0.01; 			step_increment = 1.05; 			step_size = 0.039;@@ -2888,8 +2889,8 @@ public class StrokeTool : GLib.Object { 		 			step = step_size; 			keep = 0;-			step_size = 0.05; // 0.01-+			step_size = 0.05;+			 			while (step < 1 - 2 * step_size) { 				Path.get_point_for_step (p1, p2, step, out x, out y); 				Path.get_point_for_step (p1, p2, step + step_size, out x2, out y2);@@ -2988,86 +2989,27 @@ public class StrokeTool : GLib.Object { 					add_corner (side2, previous_inside, start, p2.copy (), thickness); 				} 			}-			t1.print();-			-			if (fast) {-				EditPoint s1, s2;-				bool open;-				-				convert_to_curve (side1);-				convert_to_curve (side2);-			-				side2.reverse ();-				s1 = side1.get_last_point ().copy ();-				s2 = side2.get_first_point ().copy ();--				s1.flags &= EditPoint.CURVE ^ EditPoint.ALL;-				s2.flags &= EditPoint.CURVE ^ EditPoint.ALL;-				-				s1.convert_to_line ();-				s2.convert_to_line ();-							-				open = path.is_open ();-				-				if (!open) {-					path.reopen ();-				}-				-				pl.append (merge_stroke_parts (path, side1, side2));--				if (!open) {-					path.close ();-				}-								-				side1 = new Path ();-				side2 = new Path ();-				-				get_segment (thickness, 0, 0.00001, p2, p3, out start);-				get_segment (-thickness, 0, 0.00001, p2, p3, out start_inside);--				previous = start.copy ();-				previous_inside = start_inside.copy ();-				-				previous.flags |= EditPoint.CURVE;-				previous_inside.flags |= EditPoint.CURVE;--				side1.add_point (previous);-				side2.add_point (previous_inside);-			} 		} 		-		if (!fast) {-			side1.remove_points_on_points ();-			side2.remove_points_on_points ();+		side1.remove_points_on_points ();+		side2.remove_points_on_points ();+	+		convert_to_curve (side1);+		convert_to_curve (side2); 		-			convert_to_curve (side1);-			convert_to_curve (side2);+		side2.reverse ();		+		pl = merge_stroke_parts (path, side1, side2); 			-			side2.reverse ();-			-			Test t2 = new Test.time ("merge2");-			pl = merge_stroke_parts (path, side1, side2);-			t2.print();-		}--		if (fast) {-			foreach (Path p in pl.paths) {-				p.close ();-				convert_to_curve (p);-			}-		}-				 		return pl; 	} 	 	void convert_to_curve (Path path) { 		if (path.is_open ()) {-			path.get_first_point ().flags &= EditPoint.ALL ^ EditPoint.CURVE;-			path.get_last_point ().flags &= EditPoint.ALL ^ EditPoint.CURVE;+			path.get_first_point ().flags &= ~EditPoint.CURVE;+			path.get_last_point ().flags &= ~EditPoint.CURVE; 		} 		 		path.recalculate_linear_handles ();-		path.remove_points_on_points ();  		foreach (EditPoint ep in path.points) { 			if ((ep.flags & EditPoint.SEGMENT_END) == 0) {

Contact

Email: johan.mattsson.m@gmail.com
Mastodon: typo.social/@birdfont
GitHub: johanmattssonm
LinkedIn: johan-mattsson-2ab324112