aboutsummaryrefslogtreecommitdiffhomepage
path: root/output.cpp
diff options
context:
space:
mode:
authorGravatar ridiculousfish <corydoras@ridiculousfish.com>2012-02-07 22:44:10 -0800
committerGravatar ridiculousfish <corydoras@ridiculousfish.com>2012-02-07 22:44:10 -0800
commit8a2737566c57404a238bee8b14edff9f5ea334ed (patch)
treeb86f63be3690fd44b2e2706de88cd9b94f416f0f /output.cpp
parent006523ac59e42bc4ed2339ef31d2f6b41bdb190e (diff)
Excised some more halloc
Diffstat (limited to 'output.cpp')
-rw-r--r--output.cpp54
1 files changed, 13 insertions, 41 deletions
diff --git a/output.cpp b/output.cpp
index 32d4fe13..979d9c38 100644
--- a/output.cpp
+++ b/output.cpp
@@ -102,18 +102,7 @@ static const int col_idx[]=
6,
7,
FISH_COLOR_NORMAL,
-}
- ;
-
-/**
- Size of writestr_buff
-*/
-static size_t writestr_buff_sz=0;
-
-/**
- Temp buffer used for converting from wide to narrow strings
-*/
-static char *writestr_buff = 0;
+};
/**
The function used for output
@@ -127,14 +116,6 @@ static int (*out)(char c) = &writeb_internal;
static wchar_t *current_term = 0;
-/**
- Cleanup function. Run automatically through halloc
-*/
-static void output_destroy()
-{
- free( writestr_buff );
-}
-
void output_set_writer( int (*writer)(char) )
{
CHECK( writer, );
@@ -436,39 +417,30 @@ void writestr( const wchar_t *str )
}
len++;
-
- /*
- Reallocate if needed
- */
- if( writestr_buff_sz < len )
- {
- if( !writestr_buff )
- {
- halloc_register_function_void( global_context, &output_destroy );
- }
- writestr_buff = (char *)realloc( writestr_buff, len );
- if( !writestr_buff )
- {
- DIE_MEM();
- }
- writestr_buff_sz = len;
- }
-
/*
Convert
*/
- wcstombs( writestr_buff,
+ char *buffer, static_buffer[256];
+ if (len <= sizeof static_buffer)
+ buffer = static_buffer;
+ else
+ buffer = new char[len];
+
+ wcstombs( buffer,
str,
- writestr_buff_sz );
+ len );
/*
Write
*/
- for( pos = writestr_buff; *pos; pos++ )
+ for( pos = buffer; *pos; pos++ )
{
out( *pos );
}
+
+ if (buffer != static_buffer)
+ delete[] buffer;
}