From 971a4e484757c083c9daa68a4a3e235a549ab523 Mon Sep 17 00:00:00 2001
From: David Robillard <d@drobilla.net>
Date: Mon, 9 Feb 2015 00:30:59 +0000
Subject: Stable sort update only by depth to preserve port order.

git-svn-id: http://svn.drobilla.net/lad/trunk/ingen@5548 a436a847-0d15-0410-975c-d299462d15a1
---
 src/server/events/Get.cpp | 12 ++++++++++--
 src/server/events/Get.hpp |  4 ----
 2 files changed, 10 insertions(+), 6 deletions(-)

(limited to 'src/server')

diff --git a/src/server/events/Get.cpp b/src/server/events/Get.cpp
index 8a9eb227..c8e7a711 100644
--- a/src/server/events/Get.cpp
+++ b/src/server/events/Get.cpp
@@ -100,11 +100,19 @@ Get::Response::put_graph(const GraphImpl* graph)
 	}
 }
 
+/** Returns true if a is closer to the root than b. */
+static inline bool
+put_higher_than(const Get::Response::Put& a, const Get::Response::Put& b)
+{
+	return (std::count(a.uri.begin(), a.uri.end(), '/') <
+	        std::count(b.uri.begin(), b.uri.end(), '/'));
+}
+
 void
 Get::Response::send(Interface* dest)
 {
-	// Sort puts by URI so parents are sent first
-	std::sort(puts.begin(), puts.end());
+	// Sort puts by increasing depth so parents are sent first
+	std::stable_sort(puts.begin(), puts.end(), put_higher_than);
 	for (const Response::Put& put : puts) {
 		dest->put(put.uri, put.properties, put.ctx);
 	}
diff --git a/src/server/events/Get.hpp b/src/server/events/Get.hpp
index e0ed3483..bcb07fcb 100644
--- a/src/server/events/Get.hpp
+++ b/src/server/events/Get.hpp
@@ -74,10 +74,6 @@ public:
 			Raul::URI            uri;
 			Resource::Properties properties;
 			Resource::Graph      ctx;
-
-			inline bool operator<(const Put& other) {
-				return uri < other.uri;
-			}
 		};
 
 		struct Connect {
-- 
cgit v1.2.1