mirror of
https://github.com/tmux/tmux.git
synced 2024-12-13 01:48:47 +00:00
Sync OpenBSD patchset 1008:
Use RB trees not SPLAY.
This commit is contained in:
parent
a7b0b30bdd
commit
a3c1b730c9
@ -107,7 +107,7 @@ cmd_bind_key_table(struct cmd *self, struct cmd_ctx *ctx, int key)
|
|||||||
|
|
||||||
mtmp.key = key;
|
mtmp.key = key;
|
||||||
mtmp.mode = !!args_has(args, 'c');
|
mtmp.mode = !!args_has(args, 'c');
|
||||||
if ((mbind = SPLAY_FIND(mode_key_tree, mtab->tree, &mtmp)) != NULL) {
|
if ((mbind = RB_FIND(mode_key_tree, mtab->tree, &mtmp)) != NULL) {
|
||||||
mbind->cmd = cmd;
|
mbind->cmd = cmd;
|
||||||
return (0);
|
return (0);
|
||||||
}
|
}
|
||||||
@ -115,6 +115,6 @@ cmd_bind_key_table(struct cmd *self, struct cmd_ctx *ctx, int key)
|
|||||||
mbind->key = mtmp.key;
|
mbind->key = mtmp.key;
|
||||||
mbind->mode = mtmp.mode;
|
mbind->mode = mtmp.mode;
|
||||||
mbind->cmd = cmd;
|
mbind->cmd = cmd;
|
||||||
SPLAY_INSERT(mode_key_tree, mtab->tree, mbind);
|
RB_INSERT(mode_key_tree, mtab->tree, mbind);
|
||||||
return (0);
|
return (0);
|
||||||
}
|
}
|
||||||
|
@ -55,7 +55,7 @@ cmd_list_keys_exec(struct cmd *self, struct cmd_ctx *ctx)
|
|||||||
|
|
||||||
width = 0;
|
width = 0;
|
||||||
|
|
||||||
SPLAY_FOREACH(bd, key_bindings, &key_bindings) {
|
RB_FOREACH(bd, key_bindings, &key_bindings) {
|
||||||
key = key_string_lookup_key(bd->key & ~KEYC_PREFIX);
|
key = key_string_lookup_key(bd->key & ~KEYC_PREFIX);
|
||||||
if (key == NULL)
|
if (key == NULL)
|
||||||
continue;
|
continue;
|
||||||
@ -72,7 +72,7 @@ cmd_list_keys_exec(struct cmd *self, struct cmd_ctx *ctx)
|
|||||||
width = keywidth;
|
width = keywidth;
|
||||||
}
|
}
|
||||||
|
|
||||||
SPLAY_FOREACH(bd, key_bindings, &key_bindings) {
|
RB_FOREACH(bd, key_bindings, &key_bindings) {
|
||||||
key = key_string_lookup_key(bd->key & ~KEYC_PREFIX);
|
key = key_string_lookup_key(bd->key & ~KEYC_PREFIX);
|
||||||
if (key == NULL)
|
if (key == NULL)
|
||||||
continue;
|
continue;
|
||||||
@ -116,7 +116,7 @@ cmd_list_keys_table(struct cmd *self, struct cmd_ctx *ctx)
|
|||||||
|
|
||||||
width = 0;
|
width = 0;
|
||||||
any_mode = 0;
|
any_mode = 0;
|
||||||
SPLAY_FOREACH(mbind, mode_key_tree, mtab->tree) {
|
RB_FOREACH(mbind, mode_key_tree, mtab->tree) {
|
||||||
key = key_string_lookup_key(mbind->key);
|
key = key_string_lookup_key(mbind->key);
|
||||||
if (key == NULL)
|
if (key == NULL)
|
||||||
continue;
|
continue;
|
||||||
@ -129,7 +129,7 @@ cmd_list_keys_table(struct cmd *self, struct cmd_ctx *ctx)
|
|||||||
width = keywidth;
|
width = keywidth;
|
||||||
}
|
}
|
||||||
|
|
||||||
SPLAY_FOREACH(mbind, mode_key_tree, mtab->tree) {
|
RB_FOREACH(mbind, mode_key_tree, mtab->tree) {
|
||||||
key = key_string_lookup_key(mbind->key);
|
key = key_string_lookup_key(mbind->key);
|
||||||
if (key == NULL)
|
if (key == NULL)
|
||||||
continue;
|
continue;
|
||||||
|
@ -57,8 +57,8 @@ cmd_unbind_key_exec(struct cmd *self, unused struct cmd_ctx *ctx)
|
|||||||
int key;
|
int key;
|
||||||
|
|
||||||
if (args_has(args, 'a')) {
|
if (args_has(args, 'a')) {
|
||||||
while (!SPLAY_EMPTY(&key_bindings)) {
|
while (!RB_EMPTY(&key_bindings)) {
|
||||||
bd = SPLAY_ROOT(&key_bindings);
|
bd = RB_ROOT(&key_bindings);
|
||||||
key_bindings_remove(bd->key);
|
key_bindings_remove(bd->key);
|
||||||
}
|
}
|
||||||
return (0);
|
return (0);
|
||||||
@ -95,8 +95,8 @@ cmd_unbind_key_table(struct cmd *self, struct cmd_ctx *ctx, int key)
|
|||||||
|
|
||||||
mtmp.key = key;
|
mtmp.key = key;
|
||||||
mtmp.mode = !!args_has(args, 'c');
|
mtmp.mode = !!args_has(args, 'c');
|
||||||
if ((mbind = SPLAY_FIND(mode_key_tree, mtab->tree, &mtmp)) != NULL) {
|
if ((mbind = RB_FIND(mode_key_tree, mtab->tree, &mtmp)) != NULL) {
|
||||||
SPLAY_REMOVE(mode_key_tree, mtab->tree, mbind);
|
RB_REMOVE(mode_key_tree, mtab->tree, mbind);
|
||||||
xfree(mbind);
|
xfree(mbind);
|
||||||
}
|
}
|
||||||
return (0);
|
return (0);
|
||||||
|
@ -24,7 +24,7 @@
|
|||||||
|
|
||||||
#include "tmux.h"
|
#include "tmux.h"
|
||||||
|
|
||||||
SPLAY_GENERATE(key_bindings, key_binding, entry, key_bindings_cmp);
|
RB_GENERATE(key_bindings, key_binding, entry, key_bindings_cmp);
|
||||||
|
|
||||||
struct key_bindings key_bindings;
|
struct key_bindings key_bindings;
|
||||||
struct key_bindings dead_key_bindings;
|
struct key_bindings dead_key_bindings;
|
||||||
@ -52,7 +52,7 @@ key_bindings_lookup(int key)
|
|||||||
struct key_binding bd;
|
struct key_binding bd;
|
||||||
|
|
||||||
bd.key = key;
|
bd.key = key;
|
||||||
return (SPLAY_FIND(key_bindings, &key_bindings, &bd));
|
return (RB_FIND(key_bindings, &key_bindings, &bd));
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
@ -64,7 +64,7 @@ key_bindings_add(int key, int can_repeat, struct cmd_list *cmdlist)
|
|||||||
|
|
||||||
bd = xmalloc(sizeof *bd);
|
bd = xmalloc(sizeof *bd);
|
||||||
bd->key = key;
|
bd->key = key;
|
||||||
SPLAY_INSERT(key_bindings, &key_bindings, bd);
|
RB_INSERT(key_bindings, &key_bindings, bd);
|
||||||
|
|
||||||
bd->can_repeat = can_repeat;
|
bd->can_repeat = can_repeat;
|
||||||
bd->cmdlist = cmdlist;
|
bd->cmdlist = cmdlist;
|
||||||
@ -77,8 +77,8 @@ key_bindings_remove(int key)
|
|||||||
|
|
||||||
if ((bd = key_bindings_lookup(key)) == NULL)
|
if ((bd = key_bindings_lookup(key)) == NULL)
|
||||||
return;
|
return;
|
||||||
SPLAY_REMOVE(key_bindings, &key_bindings, bd);
|
RB_REMOVE(key_bindings, &key_bindings, bd);
|
||||||
SPLAY_INSERT(key_bindings, &dead_key_bindings, bd);
|
RB_INSERT(key_bindings, &dead_key_bindings, bd);
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
@ -86,9 +86,9 @@ key_bindings_clean(void)
|
|||||||
{
|
{
|
||||||
struct key_binding *bd;
|
struct key_binding *bd;
|
||||||
|
|
||||||
while (!SPLAY_EMPTY(&dead_key_bindings)) {
|
while (!RB_EMPTY(&dead_key_bindings)) {
|
||||||
bd = SPLAY_ROOT(&dead_key_bindings);
|
bd = RB_ROOT(&dead_key_bindings);
|
||||||
SPLAY_REMOVE(key_bindings, &dead_key_bindings, bd);
|
RB_REMOVE(key_bindings, &dead_key_bindings, bd);
|
||||||
cmd_list_free(bd->cmdlist);
|
cmd_list_free(bd->cmdlist);
|
||||||
xfree(bd);
|
xfree(bd);
|
||||||
}
|
}
|
||||||
@ -179,7 +179,7 @@ key_bindings_init(void)
|
|||||||
struct cmd *cmd;
|
struct cmd *cmd;
|
||||||
struct cmd_list *cmdlist;
|
struct cmd_list *cmdlist;
|
||||||
|
|
||||||
SPLAY_INIT(&key_bindings);
|
RB_INIT(&key_bindings);
|
||||||
|
|
||||||
for (i = 0; i < nitems(table); i++) {
|
for (i = 0; i < nitems(table); i++) {
|
||||||
cmdlist = xmalloc(sizeof *cmdlist);
|
cmdlist = xmalloc(sizeof *cmdlist);
|
||||||
|
@ -412,7 +412,7 @@ const struct mode_key_table mode_key_tables[] = {
|
|||||||
{ NULL, NULL, NULL, NULL }
|
{ NULL, NULL, NULL, NULL }
|
||||||
};
|
};
|
||||||
|
|
||||||
SPLAY_GENERATE(mode_key_tree, mode_key_binding, entry, mode_key_cmp);
|
RB_GENERATE(mode_key_tree, mode_key_binding, entry, mode_key_cmp);
|
||||||
|
|
||||||
int
|
int
|
||||||
mode_key_cmp(struct mode_key_binding *mbind1, struct mode_key_binding *mbind2)
|
mode_key_cmp(struct mode_key_binding *mbind1, struct mode_key_binding *mbind2)
|
||||||
@ -462,13 +462,13 @@ mode_key_init_trees(void)
|
|||||||
struct mode_key_binding *mbind;
|
struct mode_key_binding *mbind;
|
||||||
|
|
||||||
for (mtab = mode_key_tables; mtab->name != NULL; mtab++) {
|
for (mtab = mode_key_tables; mtab->name != NULL; mtab++) {
|
||||||
SPLAY_INIT(mtab->tree);
|
RB_INIT(mtab->tree);
|
||||||
for (ment = mtab->table; ment->mode != -1; ment++) {
|
for (ment = mtab->table; ment->mode != -1; ment++) {
|
||||||
mbind = xmalloc(sizeof *mbind);
|
mbind = xmalloc(sizeof *mbind);
|
||||||
mbind->key = ment->key;
|
mbind->key = ment->key;
|
||||||
mbind->mode = ment->mode;
|
mbind->mode = ment->mode;
|
||||||
mbind->cmd = ment->cmd;
|
mbind->cmd = ment->cmd;
|
||||||
SPLAY_INSERT(mode_key_tree, mtab->tree, mbind);
|
RB_INSERT(mode_key_tree, mtab->tree, mbind);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -487,7 +487,7 @@ mode_key_lookup(struct mode_key_data *mdata, int key)
|
|||||||
|
|
||||||
mtmp.key = key;
|
mtmp.key = key;
|
||||||
mtmp.mode = mdata->mode;
|
mtmp.mode = mdata->mode;
|
||||||
if ((mbind = SPLAY_FIND(mode_key_tree, mdata->tree, &mtmp)) == NULL) {
|
if ((mbind = RB_FIND(mode_key_tree, mdata->tree, &mtmp)) == NULL) {
|
||||||
if (mdata->mode != 0)
|
if (mdata->mode != 0)
|
||||||
return (MODEKEY_NONE);
|
return (MODEKEY_NONE);
|
||||||
return (MODEKEY_OTHER);
|
return (MODEKEY_OTHER);
|
||||||
|
22
options.c
22
options.c
@ -28,7 +28,7 @@
|
|||||||
* a splay tree.
|
* a splay tree.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
SPLAY_GENERATE(options_tree, options_entry, entry, options_cmp);
|
RB_GENERATE(options_tree, options_entry, entry, options_cmp);
|
||||||
|
|
||||||
int
|
int
|
||||||
options_cmp(struct options_entry *o1, struct options_entry *o2)
|
options_cmp(struct options_entry *o1, struct options_entry *o2)
|
||||||
@ -39,7 +39,7 @@ options_cmp(struct options_entry *o1, struct options_entry *o2)
|
|||||||
void
|
void
|
||||||
options_init(struct options *oo, struct options *parent)
|
options_init(struct options *oo, struct options *parent)
|
||||||
{
|
{
|
||||||
SPLAY_INIT(&oo->tree);
|
RB_INIT(&oo->tree);
|
||||||
oo->parent = parent;
|
oo->parent = parent;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -48,9 +48,9 @@ options_free(struct options *oo)
|
|||||||
{
|
{
|
||||||
struct options_entry *o;
|
struct options_entry *o;
|
||||||
|
|
||||||
while (!SPLAY_EMPTY(&oo->tree)) {
|
while (!RB_EMPTY(&oo->tree)) {
|
||||||
o = SPLAY_ROOT(&oo->tree);
|
o = RB_ROOT(&oo->tree);
|
||||||
SPLAY_REMOVE(options_tree, &oo->tree, o);
|
RB_REMOVE(options_tree, &oo->tree, o);
|
||||||
xfree(o->name);
|
xfree(o->name);
|
||||||
if (o->type == OPTIONS_STRING)
|
if (o->type == OPTIONS_STRING)
|
||||||
xfree(o->str);
|
xfree(o->str);
|
||||||
@ -64,7 +64,7 @@ options_find1(struct options *oo, const char *name)
|
|||||||
struct options_entry p;
|
struct options_entry p;
|
||||||
|
|
||||||
p.name = (char *) name;
|
p.name = (char *) name;
|
||||||
return (SPLAY_FIND(options_tree, &oo->tree, &p));
|
return (RB_FIND(options_tree, &oo->tree, &p));
|
||||||
}
|
}
|
||||||
|
|
||||||
struct options_entry *
|
struct options_entry *
|
||||||
@ -73,12 +73,12 @@ options_find(struct options *oo, const char *name)
|
|||||||
struct options_entry *o, p;
|
struct options_entry *o, p;
|
||||||
|
|
||||||
p.name = (char *) name;
|
p.name = (char *) name;
|
||||||
o = SPLAY_FIND(options_tree, &oo->tree, &p);
|
o = RB_FIND(options_tree, &oo->tree, &p);
|
||||||
while (o == NULL) {
|
while (o == NULL) {
|
||||||
oo = oo->parent;
|
oo = oo->parent;
|
||||||
if (oo == NULL)
|
if (oo == NULL)
|
||||||
break;
|
break;
|
||||||
o = SPLAY_FIND(options_tree, &oo->tree, &p);
|
o = RB_FIND(options_tree, &oo->tree, &p);
|
||||||
}
|
}
|
||||||
return (o);
|
return (o);
|
||||||
}
|
}
|
||||||
@ -91,7 +91,7 @@ options_remove(struct options *oo, const char *name)
|
|||||||
if ((o = options_find1(oo, name)) == NULL)
|
if ((o = options_find1(oo, name)) == NULL)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
SPLAY_REMOVE(options_tree, &oo->tree, o);
|
RB_REMOVE(options_tree, &oo->tree, o);
|
||||||
xfree(o->name);
|
xfree(o->name);
|
||||||
if (o->type == OPTIONS_STRING)
|
if (o->type == OPTIONS_STRING)
|
||||||
xfree(o->str);
|
xfree(o->str);
|
||||||
@ -107,7 +107,7 @@ options_set_string(struct options *oo, const char *name, const char *fmt, ...)
|
|||||||
if ((o = options_find1(oo, name)) == NULL) {
|
if ((o = options_find1(oo, name)) == NULL) {
|
||||||
o = xmalloc(sizeof *o);
|
o = xmalloc(sizeof *o);
|
||||||
o->name = xstrdup(name);
|
o->name = xstrdup(name);
|
||||||
SPLAY_INSERT(options_tree, &oo->tree, o);
|
RB_INSERT(options_tree, &oo->tree, o);
|
||||||
} else if (o->type == OPTIONS_STRING)
|
} else if (o->type == OPTIONS_STRING)
|
||||||
xfree(o->str);
|
xfree(o->str);
|
||||||
|
|
||||||
@ -138,7 +138,7 @@ options_set_number(struct options *oo, const char *name, long long value)
|
|||||||
if ((o = options_find1(oo, name)) == NULL) {
|
if ((o = options_find1(oo, name)) == NULL) {
|
||||||
o = xmalloc(sizeof *o);
|
o = xmalloc(sizeof *o);
|
||||||
o->name = xstrdup(name);
|
o->name = xstrdup(name);
|
||||||
SPLAY_INSERT(options_tree, &oo->tree, o);
|
RB_INSERT(options_tree, &oo->tree, o);
|
||||||
} else if (o->type == OPTIONS_STRING)
|
} else if (o->type == OPTIONS_STRING)
|
||||||
xfree(o->str);
|
xfree(o->str);
|
||||||
|
|
||||||
|
18
tmux.h
18
tmux.h
@ -541,9 +541,9 @@ struct mode_key_binding {
|
|||||||
int mode;
|
int mode;
|
||||||
enum mode_key_cmd cmd;
|
enum mode_key_cmd cmd;
|
||||||
|
|
||||||
SPLAY_ENTRY(mode_key_binding) entry;
|
RB_ENTRY(mode_key_binding) entry;
|
||||||
};
|
};
|
||||||
SPLAY_HEAD(mode_key_tree, mode_key_binding);
|
RB_HEAD(mode_key_tree, mode_key_binding);
|
||||||
|
|
||||||
/* Command to string mapping. */
|
/* Command to string mapping. */
|
||||||
struct mode_key_cmdstr {
|
struct mode_key_cmdstr {
|
||||||
@ -670,11 +670,11 @@ struct options_entry {
|
|||||||
char *str;
|
char *str;
|
||||||
long long num;
|
long long num;
|
||||||
|
|
||||||
SPLAY_ENTRY(options_entry) entry;
|
RB_ENTRY(options_entry) entry;
|
||||||
};
|
};
|
||||||
|
|
||||||
struct options {
|
struct options {
|
||||||
SPLAY_HEAD(options_tree, options_entry) tree;
|
RB_HEAD(options_tree, options_entry) tree;
|
||||||
struct options *parent;
|
struct options *parent;
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -1272,9 +1272,9 @@ struct key_binding {
|
|||||||
struct cmd_list *cmdlist;
|
struct cmd_list *cmdlist;
|
||||||
int can_repeat;
|
int can_repeat;
|
||||||
|
|
||||||
SPLAY_ENTRY(key_binding) entry;
|
RB_ENTRY(key_binding) entry;
|
||||||
};
|
};
|
||||||
SPLAY_HEAD(key_bindings, key_binding);
|
RB_HEAD(key_bindings, key_binding);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Option table entries. The option table is the user-visible part of the
|
* Option table entries. The option table is the user-visible part of the
|
||||||
@ -1379,7 +1379,7 @@ extern struct mode_key_tree mode_key_tree_emacs_edit;
|
|||||||
extern struct mode_key_tree mode_key_tree_emacs_choice;
|
extern struct mode_key_tree mode_key_tree_emacs_choice;
|
||||||
extern struct mode_key_tree mode_key_tree_emacs_copy;
|
extern struct mode_key_tree mode_key_tree_emacs_copy;
|
||||||
int mode_key_cmp(struct mode_key_binding *, struct mode_key_binding *);
|
int mode_key_cmp(struct mode_key_binding *, struct mode_key_binding *);
|
||||||
SPLAY_PROTOTYPE(mode_key_tree, mode_key_binding, entry, mode_key_cmp);
|
RB_PROTOTYPE(mode_key_tree, mode_key_binding, entry, mode_key_cmp);
|
||||||
const char *mode_key_tostring(const struct mode_key_cmdstr *,
|
const char *mode_key_tostring(const struct mode_key_cmdstr *,
|
||||||
enum mode_key_cmd);
|
enum mode_key_cmd);
|
||||||
enum mode_key_cmd mode_key_fromstring(const struct mode_key_cmdstr *,
|
enum mode_key_cmd mode_key_fromstring(const struct mode_key_cmdstr *,
|
||||||
@ -1391,7 +1391,7 @@ enum mode_key_cmd mode_key_lookup(struct mode_key_data *, int);
|
|||||||
|
|
||||||
/* options.c */
|
/* options.c */
|
||||||
int options_cmp(struct options_entry *, struct options_entry *);
|
int options_cmp(struct options_entry *, struct options_entry *);
|
||||||
SPLAY_PROTOTYPE(options_tree, options_entry, entry, options_cmp);
|
RB_PROTOTYPE(options_tree, options_entry, entry, options_cmp);
|
||||||
void options_init(struct options *, struct options *);
|
void options_init(struct options *, struct options *);
|
||||||
void options_free(struct options *);
|
void options_free(struct options *);
|
||||||
struct options_entry *options_find1(struct options *, const char *);
|
struct options_entry *options_find1(struct options *, const char *);
|
||||||
@ -1653,7 +1653,7 @@ int client_main(int, char **, int);
|
|||||||
/* key-bindings.c */
|
/* key-bindings.c */
|
||||||
extern struct key_bindings key_bindings;
|
extern struct key_bindings key_bindings;
|
||||||
int key_bindings_cmp(struct key_binding *, struct key_binding *);
|
int key_bindings_cmp(struct key_binding *, struct key_binding *);
|
||||||
SPLAY_PROTOTYPE(key_bindings, key_binding, entry, key_bindings_cmp);
|
RB_PROTOTYPE(key_bindings, key_binding, entry, key_bindings_cmp);
|
||||||
struct key_binding *key_bindings_lookup(int);
|
struct key_binding *key_bindings_lookup(int);
|
||||||
void key_bindings_add(int, int, struct cmd_list *);
|
void key_bindings_add(int, int, struct cmd_list *);
|
||||||
void key_bindings_remove(int);
|
void key_bindings_remove(int);
|
||||||
|
Loading…
Reference in New Issue
Block a user