svn commit: r286481 - projects/collation/usr.bin/localedef
Baptiste Daroussin
bapt at FreeBSD.org
Sat Aug 8 21:53:03 UTC 2015
Author: bapt
Date: Sat Aug 8 21:53:02 2015
New Revision: 286481
URL: https://svnweb.freebsd.org/changeset/base/286481
Log:
Convert ctype generation to Red Black tree
Modified:
projects/collation/usr.bin/localedef/ctype.c
Modified: projects/collation/usr.bin/localedef/ctype.c
==============================================================================
--- projects/collation/usr.bin/localedef/ctype.c Sat Aug 8 21:46:38 2015 (r286480)
+++ projects/collation/usr.bin/localedef/ctype.c Sat Aug 8 21:53:02 2015 (r286481)
@@ -35,7 +35,7 @@
#include <sys/cdefs.h>
__FBSDID("$FreeBSD$");
-#include <sys/avl.h>
+#include <sys/tree.h>
#include <stdio.h>
#include <stdlib.h>
@@ -68,24 +68,20 @@ __FBSDID("$FreeBSD$");
#define _E4 0
#define _E5 _CTYPE_T
-static avl_tree_t ctypes;
-
static wchar_t last_ctype;
+static int ctype_compare(const void *n1, const void *n2);
typedef struct ctype_node {
wchar_t wc;
int32_t ctype;
int32_t toupper;
int32_t tolower;
- avl_node_t avl;
+ RB_ENTRY(ctype_node) entry;
} ctype_node_t;
-typedef struct width_node {
- wchar_t start;
- wchar_t end;
- int8_t width;
- avl_node_t avl;
-} width_node_t;
+RB_HEAD(ctypes, ctype_node) ctypes;
+RB_PROTOTYPE(ctypes, ctype_node, entry, ctype_compare);
+RB_GENERATE(ctypes, ctype_node, entry, ctype_compare);
static int
ctype_compare(const void *n1, const void *n2)
@@ -99,8 +95,7 @@ ctype_compare(const void *n1, const void
void
init_ctype(void)
{
- avl_create(&ctypes, ctype_compare, sizeof (ctype_node_t),
- offsetof(ctype_node_t, avl));
+ RB_INIT(&ctypes);
}
@@ -172,17 +167,16 @@ get_ctype(wchar_t wc)
{
ctype_node_t srch;
ctype_node_t *ctn;
- avl_index_t where;
srch.wc = wc;
- if ((ctn = avl_find(&ctypes, &srch, &where)) == NULL) {
+ if ((ctn = RB_FIND(ctypes, &ctypes, &srch)) == NULL) {
if ((ctn = calloc(1, sizeof (*ctn))) == NULL) {
errf("out of memory");
return (NULL);
}
ctn->wc = wc;
- avl_insert(&ctypes, ctn, where);
+ RB_INSERT(ctypes, &ctypes, ctn);
}
return (ctn);
}
@@ -318,10 +312,9 @@ dump_ctype(void)
rl.mapupper[wc] = wc;
}
- for (ctn = avl_first(&ctypes); ctn; ctn = AVL_NEXT(&ctypes, ctn)) {
+ RB_FOREACH(ctn, ctypes, &ctypes) {
int conflict = 0;
-
wc = ctn->wc;
/*
More information about the svn-src-projects
mailing list