From 7d4d99422a7179fb85d7f06d8ad804703d5b31f8 Mon Sep 17 00:00:00 2001 From: Guillaume Poirier-Morency Date: Mon, 4 Jan 2016 11:39:11 -0500 Subject: [PATCH] Reduce routing complexity for the 'next' callback Improve the complexity as of #144. Traverse the linked list nodes and use the current node directly (rather than traversing it again) to describe how the routing should continue when 'next' is called. --- src/valum-router.vala | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/src/valum-router.vala b/src/valum-router.vala index 47baca903..7d7ddb42e 100644 --- a/src/valum-router.vala +++ b/src/valum-router.vala @@ -279,17 +279,16 @@ namespace Valum { ServerError, Error { var tmp_stack = new Queue (); - foreach (var route in routes) { + for (unowned List node = routes; node != null; node = node.next) { tmp_stack.clear (); - if ((route.method == null || route.method == req.method) && route.match (req, tmp_stack)) { + if ((node.data.method == null || node.data.method == req.method) && node.data.match (req, tmp_stack)) { // commit the stack pushes while (!tmp_stack.is_empty ()) stack.push_tail (tmp_stack.pop_head ()); - route.fire (req, res, (req, res) => { - unowned List current = routes.find (route); + node.data.fire (req, res, (req, res) => { // keep routing if there are more routes to explore - if (current.next != null) - if (perform_routing (current.next, req, res, stack)) + if (node.next != null) + if (perform_routing (node.next, req, res, stack)) return; throw new ClientError.NOT_FOUND ("The request URI %s was not found.", req.uri.to_string (true)); }, stack);