aboutsummaryrefslogtreecommitdiffhomepage
path: root/function.c
diff options
context:
space:
mode:
authorGravatar axel <axel@liljencrantz.se>2006-02-05 23:10:35 +1000
committerGravatar axel <axel@liljencrantz.se>2006-02-05 23:10:35 +1000
commit58667673d921a782f4a531255344983bbadb9288 (patch)
tree5c49d356be69c5b2e9b841191fb6cd7a8c8c0bae /function.c
parenta53a9aa2932a1581f278f97f9f2c0d55a031de48 (diff)
Remove duplicate line counting code. Make the remaining implementation have a two element cache.
darcs-hash:20060205131035-ac50b-885c6ba87a6d16aa48dfa7ee4608ae8891c71724.gz
Diffstat (limited to 'function.c')
-rw-r--r--function.c32
1 files changed, 10 insertions, 22 deletions
diff --git a/function.c b/function.c
index 7d174f36..260df870 100644
--- a/function.c
+++ b/function.c
@@ -18,6 +18,7 @@
#include "intern.h"
#include "event.h"
#include "reader.h"
+#include "parse_util.h"
/**
@@ -65,18 +66,6 @@ void function_destroy()
hash_destroy( &function );
}
-static int count_lineno( const wchar_t *str, int len )
-{
- int res = 0;
- int i;
- for( i=0; i<len; i++ )
- {
- if( str[i] == L'\n' )
- res++;
- }
- return res;
-}
-
void function_add( const wchar_t *name,
const wchar_t *val,
@@ -88,13 +77,12 @@ void function_add( const wchar_t *name,
wchar_t *cmd_end;
function_data_t *d;
- if( function_exists( name ) )
- function_remove( name );
+ function_remove( name );
d = malloc( sizeof( function_data_t ) );
- d->definition_offset = count_lineno( parser_get_buffer(), current_block->tok_pos );
+ d->definition_offset = parse_util_lineno( parser_get_buffer(), current_block->tok_pos );
d->cmd = wcsdup( val );
-
+
cmd_end = d->cmd + wcslen(d->cmd)-1;
while( (cmd_end>d->cmd) && wcschr( L"\n\r\t ", *cmd_end ) )
{
@@ -103,7 +91,7 @@ void function_add( const wchar_t *name,
d->desc = desc?wcsdup( desc ):0;
d->is_binding = is_binding;
- d->definition_file = reader_current_filename()?intern(reader_current_filename()):0;
+ d->definition_file = intern(reader_current_filename());
hash_put( &function, intern(name), d );
@@ -125,18 +113,18 @@ void function_remove( const wchar_t *name )
function_data_t *d;
event_t ev;
- ev.type=EVENT_ANY;
- ev.function_name=name;
- event_remove( &ev );
-
hash_remove( &function,
name,
(const void **) &key,
(const void **)&d );
- if( !d )
+ if( !key )
return;
+ ev.type=EVENT_ANY;
+ ev.function_name=name;
+ event_remove( &ev );
+
clear_function_entry( key, d );
}