sort tc classes the way they are exposed by tc; fixes #2919
Costa Tsaousis (ktsaou) committed
Oct 24, 2017 at 23:12 UTC
142e9ad1a41d91554117599fc8bc255db3f2bac7
1 file changed
+19
-4
src/plugin_tc.c
+19
-4
@@ -81,6 +81,7 @@ struct tc_device {
81
avl_tree classes_index;
82
83
struct tc_class *classes;
84
+ struct tc_class *last_class;
85
86
struct tc_device *next;
87
struct tc_device *prev;
@@ -139,11 +140,19 @@ static inline struct tc_class *tc_class_index_find(struct tc_device *st, const c
140
141
static inline void tc_class_free(struct tc_device *n, struct tc_class *c) {
142
if(c == n->classes) {
142
- if(c->next)
143
+ if(likely(c->next))
144
n->classes = c->next;
145
else
146
n->classes = c->prev;
147
}
148
+
149
+ if(c == n->last_class) {
150
+ if(unlikely(c->next))
151
+ n->last_class = c->next;
152
+ else
153
+ n->last_class = c->prev;
154
+ }
155
+
156
if(c->next) c->next->prev = c->prev;
157
if(c->prev) c->prev->next = c->next;
158
@@ -713,9 +722,15 @@ static inline struct tc_class *tc_class_add(struct tc_device *n, char *id, char
722
723
c = callocz(1, sizeof(struct tc_class));
724
716
- if(n->classes) n->classes->prev = c;
717
- c->next = n->classes;
718
- n->classes = c;
725
+ if(unlikely(!n->classes))
726
+ n->classes = c;
727
+
728
+ else if(likely(n->last_class)) {
729
+ n->last_class->next = c;
730
+ c->prev = n->last_class;
731
+ }
732
+
733
+ n->last_class = c;
734
735
c->id = strdupz(id);
736
c->hash = simple_hash(c->id);