Change to make the lookahead array a std::stack instead of a static 4k list(!)

This commit is contained in:
ridiculousfish 2012-11-24 16:58:30 -08:00
parent 464f1f44aa
commit e152cfac34
3 changed files with 65 additions and 47 deletions

View file

@ -14,6 +14,8 @@ Implementation file for the low level input library
#include <sys/types.h> #include <sys/types.h>
#include <unistd.h> #include <unistd.h>
#include <wchar.h> #include <wchar.h>
#include <stack>
#include <list>
#ifdef HAVE_SYS_SELECT_H #ifdef HAVE_SYS_SELECT_H
#include <sys/select.h> #include <sys/select.h>
#endif #endif
@ -34,15 +36,30 @@ Implementation file for the low level input library
*/ */
#define WAIT_ON_ESCAPE 10 #define WAIT_ON_ESCAPE 10
/** /** Characters that have been read and returned by the sequence matching code */
Characters that have been read and returned by the sequence matching code static std::stack<wint_t, std::list<wint_t> > lookahead_list;
*/
static wint_t lookahead_arr[1024];
/** static bool has_lookahead(void)
Number of entries in lookahead_arr {
*/ return ! lookahead_list.empty();
static int lookahead_count = 0; }
static wint_t lookahead_pop(void)
{
wint_t result = lookahead_list.top();
lookahead_list.pop();
return result;
}
static void lookahead_push(wint_t c)
{
lookahead_list.push(c);
}
static wint_t lookahead_top(void)
{
return lookahead_list.top();
}
/** Callback function for handling interrupts on reading */ /** Callback function for handling interrupts on reading */
static int (*interrupt_handler)(); static int (*interrupt_handler)();
@ -115,9 +132,9 @@ static wint_t readb()
{ {
return res; return res;
} }
if (lookahead_count) if (has_lookahead())
{ {
return lookahead_arr[--lookahead_count]; return lookahead_pop();
} }
} }
@ -144,18 +161,18 @@ static wint_t readb()
{ {
debug(3, L"Wake up on universal variable event"); debug(3, L"Wake up on universal variable event");
env_universal_read_all(); env_universal_read_all();
if (lookahead_count) if (has_lookahead())
{ {
return lookahead_arr[--lookahead_count]; return lookahead_pop();
} }
} }
if (ioport > 0 && FD_ISSET(ioport, &fdset)) if (ioport > 0 && FD_ISSET(ioport, &fdset))
{ {
iothread_service_completion(); iothread_service_completion();
if (lookahead_count) if (has_lookahead())
{ {
return lookahead_arr[--lookahead_count]; return lookahead_pop();
} }
} }
@ -179,7 +196,7 @@ static wint_t readb()
wchar_t input_common_readch(int timed) wchar_t input_common_readch(int timed)
{ {
if (lookahead_count == 0) if (! has_lookahead())
{ {
if (timed) if (timed)
{ {
@ -247,19 +264,19 @@ wchar_t input_common_readch(int timed)
{ {
if (!timed) if (!timed)
{ {
while ((lookahead_count >= 0) && (lookahead_arr[lookahead_count-1] == WEOF)) while (has_lookahead() && lookahead_top() == WEOF)
lookahead_count--; lookahead_pop();
if (lookahead_count == 0) if (! has_lookahead())
return input_common_readch(0); return input_common_readch(0);
} }
return lookahead_arr[--lookahead_count]; return lookahead_pop();
} }
} }
void input_common_unreadch(wint_t ch) void input_common_unreadch(wint_t ch)
{ {
lookahead_arr[lookahead_count++] = ch; lookahead_push(ch);
} }

View file

@ -217,7 +217,8 @@ void s_write(screen_t *s,
void s_reset(screen_t *s, bool reset_cursor, bool reset_prompt = true); void s_reset(screen_t *s, bool reset_cursor, bool reset_prompt = true);
enum screen_reset_mode_t { enum screen_reset_mode_t
{
/* Do not make a new line, do not repaint the prompt. */ /* Do not make a new line, do not repaint the prompt. */
screen_reset_current_line_contents, screen_reset_current_line_contents,