diff options
author | Nicholas Marriott <nicholas.marriott@gmail.com> | 2009-05-04 18:05:23 +0000 |
---|---|---|
committer | Nicholas Marriott <nicholas.marriott@gmail.com> | 2009-05-04 18:05:23 +0000 |
commit | 525bd431b236ef8ce2275ed46072e90381c01604 (patch) | |
tree | cf40f8f82ce90dc03c05fee578336a4cd6dc3abd /tty-keys.c | |
parent | 143aa718e5958b9c7b539657d02c476a43270dad (diff) | |
download | rtmux-525bd431b236ef8ce2275ed46072e90381c01604.tar.gz rtmux-525bd431b236ef8ce2275ed46072e90381c01604.tar.bz2 rtmux-525bd431b236ef8ce2275ed46072e90381c01604.zip |
RB_INSERT returns &item if already exists, so use that rather than doing a
check beforehand.
Diffstat (limited to 'tty-keys.c')
-rw-r--r-- | tty-keys.c | 20 |
1 files changed, 9 insertions, 11 deletions
@@ -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> @@ -131,24 +131,22 @@ tty_keys_cmp(struct tty_key *k1, struct tty_key *k2) void tty_keys_add(struct tty *tty, const char *s, int key, int flags) { - 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; - } + struct tty_key *tk, *tl; tk = xmalloc(sizeof *tk); tk->string = xstrdup(s); tk->key = key; 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) 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); } |