mirror of
https://github.com/Ed94/gencpp.git
synced 2024-12-22 15:54:45 -08:00
Removed usage of hashtable member procs
This commit is contained in:
parent
31a3609b28
commit
0b4ccac8f9
@ -282,7 +282,7 @@ void init()
|
|||||||
|
|
||||||
// Setup the hash tables
|
// Setup the hash tables
|
||||||
{
|
{
|
||||||
StringCache = StringTable::init( Allocator_StringTable );
|
StringCache = hashtable_init<StringCached>(Allocator_StringTable);
|
||||||
|
|
||||||
if ( StringCache.Entries == nullptr )
|
if ( StringCache.Entries == nullptr )
|
||||||
GEN_FATAL( "gen::init: Failed to initialize the StringCache");
|
GEN_FATAL( "gen::init: Failed to initialize the StringCache");
|
||||||
@ -317,7 +317,7 @@ void deinit()
|
|||||||
}
|
}
|
||||||
while ( left--, left );
|
while ( left--, left );
|
||||||
|
|
||||||
StringCache.destroy();
|
destroy(StringCache);
|
||||||
|
|
||||||
free(CodePools);
|
free(CodePools);
|
||||||
free(StringArenas);
|
free(StringArenas);
|
||||||
@ -392,14 +392,14 @@ StringCached get_cached_string( StrC str )
|
|||||||
s32 hash_length = str.Len > kilobytes(1) ? kilobytes(1) : str.Len;
|
s32 hash_length = str.Len > kilobytes(1) ? kilobytes(1) : str.Len;
|
||||||
u64 key = crc32( str.Ptr, hash_length );
|
u64 key = crc32( str.Ptr, hash_length );
|
||||||
{
|
{
|
||||||
StringCached* result = StringCache.get( key );
|
StringCached* result = get(StringCache, key );
|
||||||
|
|
||||||
if ( result )
|
if ( result )
|
||||||
return * result;
|
return * result;
|
||||||
}
|
}
|
||||||
|
|
||||||
String result = String::make( get_string_allocator( str.Len ), str );
|
String result = String::make( get_string_allocator( str.Len ), str );
|
||||||
StringCache.set( key, result );
|
set<StringCached>(StringCache, key, result );
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
@ -17,7 +17,7 @@ ssize token_fmt_va( char* buf, usize buf_size, s32 num_tokens, va_list va )
|
|||||||
char tok_map_mem[ TokenFmt_TokenMap_MemSize ];
|
char tok_map_mem[ TokenFmt_TokenMap_MemSize ];
|
||||||
|
|
||||||
tok_map_arena = arena_init_from_memory( tok_map_mem, sizeof(tok_map_mem) );
|
tok_map_arena = arena_init_from_memory( tok_map_mem, sizeof(tok_map_mem) );
|
||||||
tok_map = HashTable<StrC>::init( allocator_info(tok_map_arena) );
|
tok_map = hashtable_init<StrC>( allocator_info(tok_map_arena) );
|
||||||
|
|
||||||
s32 left = num_tokens - 1;
|
s32 left = num_tokens - 1;
|
||||||
|
|
||||||
@ -28,7 +28,7 @@ ssize token_fmt_va( char* buf, usize buf_size, s32 num_tokens, va_list va )
|
|||||||
|
|
||||||
u32 key = crc32( token, str_len(token) );
|
u32 key = crc32( token, str_len(token) );
|
||||||
|
|
||||||
tok_map.set( key, value );
|
set(tok_map, key, value );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -64,7 +64,7 @@ ssize token_fmt_va( char* buf, usize buf_size, s32 num_tokens, va_list va )
|
|||||||
char const* token = fmt + 1;
|
char const* token = fmt + 1;
|
||||||
|
|
||||||
u32 key = crc32( token, tok_len );
|
u32 key = crc32( token, tok_len );
|
||||||
StrC* value = tok_map.get( key );
|
StrC* value = get(tok_map, key );
|
||||||
|
|
||||||
if ( value )
|
if ( value )
|
||||||
{
|
{
|
||||||
@ -94,7 +94,7 @@ ssize token_fmt_va( char* buf, usize buf_size, s32 num_tokens, va_list va )
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
tok_map.clear();
|
clear(tok_map);
|
||||||
free(tok_map_arena);
|
free(tok_map_arena);
|
||||||
|
|
||||||
ssize result = buf_size - remaining;
|
ssize result = buf_size - remaining;
|
||||||
|
@ -341,7 +341,7 @@ s32 lex_preprocessor_directive(
|
|||||||
append(Tokens, name );
|
append(Tokens, name );
|
||||||
|
|
||||||
u64 key = crc32( name.Text, name.Length );
|
u64 key = crc32( name.Text, name.Length );
|
||||||
defines.set( key, name );
|
set<StrC>(defines, key, name );
|
||||||
}
|
}
|
||||||
|
|
||||||
Token preprocess_content = { scanner, 0, TokType::Preprocess_Content, line, column, TF_Preprocess };
|
Token preprocess_content = { scanner, 0, TokType::Preprocess_Content, line, column, TF_Preprocess };
|
||||||
@ -516,7 +516,7 @@ void lex_found_token( StrC& content
|
|||||||
else
|
else
|
||||||
key = crc32( token.Text, token.Length );
|
key = crc32( token.Text, token.Length );
|
||||||
|
|
||||||
StrC* define = defines.get( key );
|
StrC* define = get(defines, key );
|
||||||
if ( define )
|
if ( define )
|
||||||
{
|
{
|
||||||
token.Type = TokType::Preprocess_Macro;
|
token.Type = TokType::Preprocess_Macro;
|
||||||
@ -597,7 +597,7 @@ TokArray lex( StrC content )
|
|||||||
}
|
}
|
||||||
|
|
||||||
u64 key = crc32( entry.Data, length );
|
u64 key = crc32( entry.Data, length );
|
||||||
defines.set( key, entry );
|
set<StrC>(defines, key, entry );
|
||||||
}
|
}
|
||||||
|
|
||||||
clear(Tokens);
|
clear(Tokens);
|
||||||
@ -1259,7 +1259,7 @@ TokArray lex( StrC content )
|
|||||||
return { { nullptr }, 0 };
|
return { { nullptr }, 0 };
|
||||||
}
|
}
|
||||||
|
|
||||||
defines.clear();
|
clear(defines);
|
||||||
// defines_map_arena.free();
|
// defines_map_arena.free();
|
||||||
return { Tokens, 0 };
|
return { Tokens, 0 };
|
||||||
}
|
}
|
||||||
|
@ -137,7 +137,7 @@ void init()
|
|||||||
);
|
);
|
||||||
|
|
||||||
fixed_arena_init(defines_map_arena);
|
fixed_arena_init(defines_map_arena);
|
||||||
defines = HashTable<StrC>::init_reserve( allocator_info(defines_map_arena), 256 );
|
defines = hashtable_init_reserve<StrC>( allocator_info(defines_map_arena), 256 );
|
||||||
}
|
}
|
||||||
|
|
||||||
internal
|
internal
|
||||||
|
@ -352,6 +352,28 @@ bool set_capacity(Array<Type>& array, usize new_capacity)
|
|||||||
Data = rcast(Type*, new_header + 1);
|
Data = rcast(Type*, new_header + 1);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#define array_init(Type, allocator) array_init<Type>(allocator)
|
||||||
|
#define array_init(Type, allocator) array_init<Type>(allocator)
|
||||||
|
#define array_init_reserve(Type, allocator, capacity) array_init_reserve<Type>(allocator, capacity)
|
||||||
|
#define array_append(Type, array, other) append<Type>(array, other)
|
||||||
|
#define array_append_value(Type, array, value) append<Type>(array, value)
|
||||||
|
#define array_append_items(Type, array, items, item_num) append<Type>(array, items, item_num)
|
||||||
|
#define array_append_at(Type, array, item, idx) append_at<Type>(array, item, idx)
|
||||||
|
#define array_append_items_at(Type, array, items, num, idx) append_at<Type>(array, items, num, idx)
|
||||||
|
#define array_back(Type, array) back<Type>(array)
|
||||||
|
#define array_clear(Type, array) clear<Type>(array)
|
||||||
|
#define array_fill(Type, array, begin, end, value) fill<Type>(array, begin, end, value)
|
||||||
|
#define array_free(Type, array) free<Type>(array)
|
||||||
|
#define array_grow(Type, array, min_capacity) grow<Type>(array, min_capacity)
|
||||||
|
#define array_num(Type, array) num<Type>(array)
|
||||||
|
#define array_pop(Type, array) pop<Type>(array)
|
||||||
|
#define array_remove_at(Type, array, idx) remove_at<Type>(array, idx)
|
||||||
|
#define array_reserve(Type, array, new_capacity) reserve<Type>(array, new_capacity)
|
||||||
|
#define array_resize(Type, array, num) resize<Type>(array, num)
|
||||||
|
#define array_set_capacity(Type, array, new_capacity) set_capacity<Type>(array, new_capacity)
|
||||||
|
#define array_get_header(array) get_header(array)
|
||||||
|
|
||||||
#pragma endregion Array
|
#pragma endregion Array
|
||||||
|
|
||||||
// TODO(Ed) : This thing needs ALOT of work.
|
// TODO(Ed) : This thing needs ALOT of work.
|
||||||
@ -372,7 +394,8 @@ struct HashTableEntry {
|
|||||||
Type Value;
|
Type Value;
|
||||||
};
|
};
|
||||||
|
|
||||||
// Forward declarations for all lifted functions
|
#define HashTableEntry(Type) HashTableEntry<Type>
|
||||||
|
|
||||||
template<class Type> HashTable<Type> hashtable_init(AllocatorInfo allocator);
|
template<class Type> HashTable<Type> hashtable_init(AllocatorInfo allocator);
|
||||||
template<class Type> HashTable<Type> hashtable_init_reserve(AllocatorInfo allocator, usize num);
|
template<class Type> HashTable<Type> hashtable_init_reserve(AllocatorInfo allocator, usize num);
|
||||||
template<class Type> void clear(HashTable<Type>& table);
|
template<class Type> void clear(HashTable<Type>& table);
|
||||||
@ -399,7 +422,7 @@ struct HashTable
|
|||||||
Array<ssize> Hashes;
|
Array<ssize> Hashes;
|
||||||
Array<HashTableEntry<Type>> Entries;
|
Array<HashTableEntry<Type>> Entries;
|
||||||
|
|
||||||
#if 1
|
#if GEN_SUPPORT_CPP_MEMBER_FEATURES
|
||||||
#pragma region Member Mapping
|
#pragma region Member Mapping
|
||||||
forceinline static HashTable init(AllocatorInfo allocator) { return GEN_NS hashtable_init<Type>(allocator); }
|
forceinline static HashTable init(AllocatorInfo allocator) { return GEN_NS hashtable_init<Type>(allocator); }
|
||||||
forceinline static HashTable init_reserve(AllocatorInfo allocator, usize num) { return GEN_NS hashtable_init_reserve<Type>(allocator, num); }
|
forceinline static HashTable init_reserve(AllocatorInfo allocator, usize num) { return GEN_NS hashtable_init_reserve<Type>(allocator, num); }
|
||||||
@ -634,6 +657,25 @@ bool full(HashTable<Type>& table) {
|
|||||||
b32 result = num(table.Entries) > critical_load;
|
b32 result = num(table.Entries) > critical_load;
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#define hashtable_init(Type, allocator) hashtable_init<Type>(allocator)
|
||||||
|
#define hashtable_init_reserve(Type, allocator, num) hashtable_init_reserve<Type>(allocator, num)
|
||||||
|
#define hashtable_clear(Type, table) clear<Type>(table)
|
||||||
|
#define hashtable_destroy(Type, table) destroy<Type>(table)
|
||||||
|
#define hashtable_get(Type, table, key) get<Type>(table, key)
|
||||||
|
#define hashtable_grow(Type, table) grow<Type>(table)
|
||||||
|
#define hashtable_rehash(Type, table, new_num) rehash<Type>(table, new_num)
|
||||||
|
#define hashtable_rehash_fast(Type, table) rehash_fast<Type>(table)
|
||||||
|
#define hashtable_remove(Type, table, key) remove<Type>(table, key)
|
||||||
|
#define hashtable_remove_entry(Type, table, idx) remove_entry<Type>(table, idx)
|
||||||
|
#define hashtable_set(Type, table, key, value) set<Type>(table, key, value)
|
||||||
|
#define hashtable_slot(Type, table, key) slot<Type>(table, key)
|
||||||
|
#define hashtable_add_entry(Type, table, key) add_entry<Type>(table, key)
|
||||||
|
#define hashtable_find(Type, table, key) find<Type>(table, key)
|
||||||
|
#define hashtable_full(Type, table) full<Type>(table)
|
||||||
|
#define hashtable_map(Type, table, map_proc) map<Type>(table, map_proc)
|
||||||
|
#define hashtable_map_mut(Type, table, map_proc) map_mut<Type>(table, map_proc)
|
||||||
|
|
||||||
#pragma endregion HashTable
|
#pragma endregion HashTable
|
||||||
|
|
||||||
#pragma endregion Containers
|
#pragma endregion Containers
|
||||||
|
@ -447,7 +447,7 @@ char* adt_parse_number_strict( ADT_Node* node, char* base_str )
|
|||||||
while ( *e )
|
while ( *e )
|
||||||
++e;
|
++e;
|
||||||
|
|
||||||
while ( *p && ( str_find( "eE.+-", *p ) || char_is_hex_digit( *p ) ) )
|
while ( *p && ( char_first_occurence( "eE.+-", *p ) || char_is_hex_digit( *p ) ) )
|
||||||
{
|
{
|
||||||
++p;
|
++p;
|
||||||
}
|
}
|
||||||
@ -476,7 +476,7 @@ char* adt_parse_number( ADT_Node* node, char* base_str )
|
|||||||
u8 node_props = 0;
|
u8 node_props = 0;
|
||||||
|
|
||||||
/* skip false positives and special cases */
|
/* skip false positives and special cases */
|
||||||
if ( ! ! str_find( "eE", *p ) || ( ! ! str_find( ".+-", *p ) && ! char_is_hex_digit( *( p + 1 ) ) && *( p + 1 ) != '.' ) )
|
if ( ! ! char_first_occurence( "eE", *p ) || ( ! ! char_first_occurence( ".+-", *p ) && ! char_is_hex_digit( *( p + 1 ) ) && *( p + 1 ) != '.' ) )
|
||||||
{
|
{
|
||||||
return ++base_str;
|
return ++base_str;
|
||||||
}
|
}
|
||||||
@ -552,7 +552,7 @@ char* adt_parse_number( ADT_Node* node, char* base_str )
|
|||||||
char expbuf[ 6 ] = { 0 };
|
char expbuf[ 6 ] = { 0 };
|
||||||
ssize expi = 0;
|
ssize expi = 0;
|
||||||
|
|
||||||
if ( *e && ! ! str_find( "eE", *e ) )
|
if ( *e && ! ! char_first_occurence( "eE", *e ) )
|
||||||
{
|
{
|
||||||
++e;
|
++e;
|
||||||
if ( *e == '+' || *e == '-' || char_is_digit( *e ) )
|
if ( *e == '+' || *e == '-' || char_is_digit( *e ) )
|
||||||
@ -748,7 +748,7 @@ ADT_Error adt_print_string( FileInfo* file, ADT_Node* node, char const* escaped_
|
|||||||
{
|
{
|
||||||
p = str_skip_any( p, escaped_chars );
|
p = str_skip_any( p, escaped_chars );
|
||||||
_adt_fprintf( file, "%.*s", pointer_diff( b, p ), b );
|
_adt_fprintf( file, "%.*s", pointer_diff( b, p ), b );
|
||||||
if ( *p && ! ! str_find( escaped_chars, *p ) )
|
if ( *p && ! ! char_first_occurence( escaped_chars, *p ) )
|
||||||
{
|
{
|
||||||
_adt_fprintf( file, "%s%c", escape_symbol, *p );
|
_adt_fprintf( file, "%s%c", escape_symbol, *p );
|
||||||
p++;
|
p++;
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
#define GEN_SUPPORT_CPP_MEMBER_FEATURES 1
|
#define GEN_SUPPORT_CPP_MEMBER_FEATURES 0
|
||||||
|
|
||||||
#ifdef GEN_INTELLISENSE_DIRECTIVES
|
#ifdef GEN_INTELLISENSE_DIRECTIVES
|
||||||
# pragma once
|
# pragma once
|
||||||
|
@ -6,7 +6,6 @@
|
|||||||
#pragma region String Ops
|
#pragma region String Ops
|
||||||
|
|
||||||
const char* char_first_occurence( const char* str, char c );
|
const char* char_first_occurence( const char* str, char c );
|
||||||
constexpr auto str_find = &char_first_occurence;
|
|
||||||
|
|
||||||
b32 char_is_alpha( char c );
|
b32 char_is_alpha( char c );
|
||||||
b32 char_is_alphanumeric( char c );
|
b32 char_is_alphanumeric( char c );
|
||||||
|
Loading…
Reference in New Issue
Block a user