Project::OSiRiON - Git repositories
Project::OSiRiON
News . About . Screenshots . Downloads . Forum . Wiki . Tracker . Git
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorStijn Buys <ingar@osirion.org>2010-11-09 12:43:23 +0000
committerStijn Buys <ingar@osirion.org>2010-11-09 12:43:23 +0000
commitfdcff7183b035a27ff960f347b9975ab8e67a3cd (patch)
tree03b009c44804d726a8687ad2f622055e28e0f809 /src/ui/listview.cc
parentbaf6ad1f48ef08187f50247115c09a3612ebeec3 (diff)
optimized ui:ListView::sort(): replaced bubblesort routine with std::list::sort()
Diffstat (limited to 'src/ui/listview.cc')
-rw-r--r--src/ui/listview.cc30
1 files changed, 16 insertions, 14 deletions
diff --git a/src/ui/listview.cc b/src/ui/listview.cc
index 70ecf8f..32d86dd 100644
--- a/src/ui/listview.cc
+++ b/src/ui/listview.cc
@@ -97,22 +97,24 @@ bool ListView::on_emit(Widget *sender, const Event event, void *data)
return false;
}
-void ListView::sort()
+bool compare_listitems(const Widget *first, const Widget *second)
{
- // bubble sort - there's a reason for using it here
- for (Children::iterator low = children().begin(); low != children().end(); low++) {
- Children::iterator high = low;
- for (high++; high != children().end(); high++) {
- ListItem *lowitem = dynamic_cast<ListItem *>(*low);
- ListItem *highitem = dynamic_cast<ListItem *>(*high);
- assert(lowitem && highitem);
- if (highitem->sortkey() < lowitem->sortkey()) {
- Widget *t = (*low);
- (*low) = (*high);
- (*high) = t;
- }
- }
+ const ListItem *firstitem = dynamic_cast<const ListItem *>(first);
+ const ListItem *seconditem = dynamic_cast<const ListItem *>(second);
+ assert(firstitem && seconditem);
+
+ if (firstitem->sortkey() < seconditem->sortkey()) {
+ return true;
+ } else if (firstitem->sortkey() > seconditem->sortkey()) {
+ return false;
+ } else {
+ return (firstitem->sortkey().length() < seconditem->sortkey().length());
}
}
+void ListView::sort()
+{
+ children().sort(compare_listitems);
+}
+
}