mirror of
https://github.com/tmux/tmux.git
synced 2024-11-17 18:08:51 +00:00
RB_INSERT returns &item if already exists, so use that rather than doing a
check beforehand.
This commit is contained in:
parent
143aa718e5
commit
525bd431b2
20
tty-keys.c
20
tty-keys.c
@ -1,4 +1,4 @@
|
|||||||
/* $Id: tty-keys.c,v 1.26 2009-05-04 17:58:27 nicm Exp $ */
|
/* $Id: tty-keys.c,v 1.27 2009-05-04 18:05:23 nicm Exp $ */
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net>
|
* Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net>
|
||||||
@ -131,24 +131,22 @@ tty_keys_cmp(struct tty_key *k1, struct tty_key *k2)
|
|||||||
void
|
void
|
||||||
tty_keys_add(struct tty *tty, const char *s, int key, int flags)
|
tty_keys_add(struct tty *tty, const char *s, int key, int flags)
|
||||||
{
|
{
|
||||||
struct tty_key *tk, tl;
|
struct tty_key *tk, *tl;
|
||||||
|
|
||||||
tl.string = s;
|
|
||||||
if ((tk = RB_FIND(tty_keys, &tty->ktree, &tl)) != NULL) {
|
|
||||||
log_debug("already key matching: %s (old %x, new %x)",
|
|
||||||
tk->string, tk->key, key);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
tk = xmalloc(sizeof *tk);
|
tk = xmalloc(sizeof *tk);
|
||||||
tk->string = xstrdup(s);
|
tk->string = xstrdup(s);
|
||||||
tk->key = key;
|
tk->key = key;
|
||||||
tk->flags = flags;
|
tk->flags = flags;
|
||||||
|
|
||||||
|
if ((tl = RB_INSERT(tty_keys, &tty->ktree, tk)) != NULL) {
|
||||||
|
xfree(tk->string);
|
||||||
|
xfree(tk);
|
||||||
|
log_debug("key exists: %s (old %x, new %x)", s, tl->key, key);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
if (strlen(tk->string) > tty->ksize)
|
if (strlen(tk->string) > tty->ksize)
|
||||||
tty->ksize = strlen(tk->string);
|
tty->ksize = strlen(tk->string);
|
||||||
RB_INSERT(tty_keys, &tty->ktree, tk);
|
|
||||||
|
|
||||||
log_debug("new key %x: size now %zu (%s)", key, tty->ksize, tk->string);
|
log_debug("new key %x: size now %zu (%s)", key, tty->ksize, tk->string);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user