Cleanup compareBuffers

This commit is contained in:
Simon Ser 2021-03-09 12:04:12 +01:00
parent 5fea13df0a
commit c83a74cc50

View File

@ -67,28 +67,22 @@ function debounce(f, delay) {
}; };
} }
function isServerBuffer(buf) {
return buf.type == BufferType.SERVER;
}
/* Returns 1 if a should appear after b, -1 if a should appear before b, or
* 0 otherwise. */
function compareBuffers(a, b) { function compareBuffers(a, b) {
if (a.network < b.network) { if (a.network != b.network) {
return -1; return a.network > b.network ? 1 : -1;
} }
if (a.network > b.network) { if (isServerBuffer(a) != isServerBuffer(b)) {
return 1; return isServerBuffer(b) ? 1 : -1;
} }
if (a.name != b.name) {
if (a.type == BufferType.SERVER) { return a.name > b.name ? 1 : -1;
return -1;
} }
if (b.type == BufferType.SERVER) {
return 1;
}
if (a.name < b.name) {
return -1;
}
if (a.name > b.name) {
return 1;
}
return 0; return 0;
} }