From 93f797326e2824dee84ca13eab19fa7782108a68 Mon Sep 17 00:00:00 2001 From: David Frascone Date: Fri, 5 Nov 2010 09:22:28 -0600 Subject: [PATCH] Optimized the result of the xsel check, so that it is cached. It is called very often, and causes a significant performace hit. The availability of xsel is not likely to change during the invocation of the shell. --- kill.c | 20 +++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-) diff --git a/kill.c b/kill.c index 002da998d..33201e1b7 100644 --- a/kill.c +++ b/kill.c @@ -45,19 +45,25 @@ static ll_node_t /** Last kill string */*kill_last=0, /** Current kill string */ static wchar_t *cut_buffer=0; /** - Test if the xsel command is installed + Test if the xsel command is installed. Since this is called often, + cache the result. */ static int has_xsel() { - void *context = halloc(0, 0); - wchar_t *path = path_get_path( context, L"xsel" ); - int res = !!path; - halloc_free( context ); + static int called=0; + static int res = 0; + + if (!called) { + void *context = halloc(0, 0); + wchar_t *path = path_get_path( context, L"xsel" ); + res = !!path; + halloc_free( context ); + called = 1; + } + return res; } - - /** Add the string to the internal killring */