From f435e8d3fa0cf50fa7db643c8d4e698292581467 Mon Sep 17 00:00:00 2001 From: Sebastien Helleu Date: Fri, 15 Nov 2013 09:01:19 +0100 Subject: core: optimize loop when closing several buffers with command /buffer close n1-n2 --- src/core/wee-command.c | 29 ++++++++++++++--------------- 1 file changed, 14 insertions(+), 15 deletions(-) (limited to 'src/core/wee-command.c') diff --git a/src/core/wee-command.c b/src/core/wee-command.c index 2af76305f..815a647f7 100644 --- a/src/core/wee-command.c +++ b/src/core/wee-command.c @@ -801,26 +801,25 @@ COMMAND_CALLBACK(buffer) { error_main_buffer = 0; num_buffers = 0; - for (i = number2; i >= number1; i--) + ptr_buffer = last_gui_buffer; + while (ptr_buffer) { - ptr_buffer = last_gui_buffer; - while (ptr_buffer) + ptr_prev_buffer = ptr_buffer->prev_buffer; + if (ptr_buffer->number < number1) + break; + if (ptr_buffer->number <= number2) { - ptr_prev_buffer = ptr_buffer->prev_buffer; - if (ptr_buffer->number == i) + num_buffers++; + if (ptr_buffer == weechat_buffer) { - num_buffers++; - if (ptr_buffer == weechat_buffer) - { - error_main_buffer = 1; - } - else - { - gui_buffer_close (ptr_buffer); - } + error_main_buffer = 1; + } + else + { + gui_buffer_close (ptr_buffer); } - ptr_buffer = ptr_prev_buffer; } + ptr_buffer = ptr_prev_buffer; } /* * display error for main buffer if it was the only -- cgit v1.2.3