lkml.org 
[lkml]   [2010]   [Jul]   [27]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
Patch in this message
/
Date
From
Subject[PATCH 07/12] jump label v10: use lib/sort.c
Make use of the the kernel's generic sort routines.

Signed-off-by: Jason Baron <jbaron@redhat.com>
---
kernel/jump_label.c | 37 ++++++++++++++++---------------------
1 files changed, 16 insertions(+), 21 deletions(-)

diff --git a/kernel/jump_label.c b/kernel/jump_label.c
index 10fb17f..faef97e 100644
--- a/kernel/jump_label.c
+++ b/kernel/jump_label.c
@@ -12,6 +12,7 @@
#include <linux/jhash.h>
#include <linux/slab.h>
#include <linux/err.h>
+#include <linux/sort.h>

#ifdef HAVE_JUMP_LABEL

@@ -38,33 +39,27 @@ struct jump_label_module_entry {
struct module *mod;
};

-static void swap_jump_label_entries(struct jump_entry *previous, struct jump_entry *next)
+static int jump_label_cmp(const void *a, const void *b)
{
- struct jump_entry tmp;
+ const struct jump_entry *jea = a;
+ const struct jump_entry *jeb = b;

- tmp = *next;
- *next = *previous;
- *previous = tmp;
+ if (jea->key < jeb->key)
+ return -1;
+
+ if (jea->key > jeb->key)
+ return 1;
+
+ return 0;
}

static void sort_jump_label_entries(struct jump_entry *start, struct jump_entry *stop)
{
- int swapped = 0;
- struct jump_entry *iter;
- struct jump_entry *iter_next;
-
- do {
- swapped = 0;
- iter = start;
- iter_next = start;
- iter_next++;
- for (; iter_next < stop; iter++, iter_next++) {
- if (iter->key > iter_next->key) {
- swap_jump_label_entries(iter, iter_next);
- swapped = 1;
- }
- }
- } while (swapped == 1);
+ unsigned long size;
+
+ size = (((unsigned long)stop - (unsigned long)start)
+ / sizeof(struct jump_entry));
+ sort(start, size, sizeof(struct jump_entry), jump_label_cmp, NULL);
}

static struct jump_label_entry *get_jump_label_entry(jump_label_t key)
--
1.7.1


\
 
 \ /
  Last update: 2010-07-27 22:57    [W:1.166 / U:0.032 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site