From 0b4ccac8f9321e47dc7bfc645bde9684a3da97dc Mon Sep 17 00:00:00 2001 From: Ed_ Date: Sun, 1 Dec 2024 01:39:21 -0500 Subject: [PATCH] Removed usage of hashtable member procs --- project/components/interface.cpp | 8 ++--- project/components/interface.untyped.cpp | 10 +++--- project/components/lexer.cpp | 8 ++--- project/components/parser.cpp | 2 +- project/dependencies/containers.hpp | 46 ++++++++++++++++++++++-- project/dependencies/parsing.cpp | 8 ++--- project/dependencies/platform.hpp | 2 +- project/dependencies/string_ops.hpp | 1 - 8 files changed, 63 insertions(+), 22 deletions(-) diff --git a/project/components/interface.cpp b/project/components/interface.cpp index 3d22496..5aadb92 100644 --- a/project/components/interface.cpp +++ b/project/components/interface.cpp @@ -282,7 +282,7 @@ void init() // Setup the hash tables { - StringCache = StringTable::init( Allocator_StringTable ); + StringCache = hashtable_init(Allocator_StringTable); if ( StringCache.Entries == nullptr ) GEN_FATAL( "gen::init: Failed to initialize the StringCache"); @@ -317,7 +317,7 @@ void deinit() } while ( left--, left ); - StringCache.destroy(); + destroy(StringCache); free(CodePools); free(StringArenas); @@ -392,14 +392,14 @@ StringCached get_cached_string( StrC str ) s32 hash_length = str.Len > kilobytes(1) ? kilobytes(1) : str.Len; u64 key = crc32( str.Ptr, hash_length ); { - StringCached* result = StringCache.get( key ); + StringCached* result = get(StringCache, key ); if ( result ) return * result; } String result = String::make( get_string_allocator( str.Len ), str ); - StringCache.set( key, result ); + set(StringCache, key, result ); return result; } diff --git a/project/components/interface.untyped.cpp b/project/components/interface.untyped.cpp index bdb0742..217a5d2 100644 --- a/project/components/interface.untyped.cpp +++ b/project/components/interface.untyped.cpp @@ -6,7 +6,7 @@ ssize token_fmt_va( char* buf, usize buf_size, s32 num_tokens, va_list va ) { char const* buf_begin = buf; - ssize remaining = buf_size; + ssize remaining = buf_size; local_persist Arena tok_map_arena; @@ -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 ]; tok_map_arena = arena_init_from_memory( tok_map_mem, sizeof(tok_map_mem) ); - tok_map = HashTable::init( allocator_info(tok_map_arena) ); + tok_map = hashtable_init( allocator_info(tok_map_arena) ); 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) ); - 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; u32 key = crc32( token, tok_len ); - StrC* value = tok_map.get( key ); + StrC* value = get(tok_map, key ); 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); ssize result = buf_size - remaining; diff --git a/project/components/lexer.cpp b/project/components/lexer.cpp index 12788a8..fe8cc94 100644 --- a/project/components/lexer.cpp +++ b/project/components/lexer.cpp @@ -341,7 +341,7 @@ s32 lex_preprocessor_directive( append(Tokens, name ); u64 key = crc32( name.Text, name.Length ); - defines.set( key, name ); + set(defines, key, name ); } Token preprocess_content = { scanner, 0, TokType::Preprocess_Content, line, column, TF_Preprocess }; @@ -516,7 +516,7 @@ void lex_found_token( StrC& content else key = crc32( token.Text, token.Length ); - StrC* define = defines.get( key ); + StrC* define = get(defines, key ); if ( define ) { token.Type = TokType::Preprocess_Macro; @@ -597,7 +597,7 @@ TokArray lex( StrC content ) } u64 key = crc32( entry.Data, length ); - defines.set( key, entry ); + set(defines, key, entry ); } clear(Tokens); @@ -1259,7 +1259,7 @@ TokArray lex( StrC content ) return { { nullptr }, 0 }; } - defines.clear(); + clear(defines); // defines_map_arena.free(); return { Tokens, 0 }; } diff --git a/project/components/parser.cpp b/project/components/parser.cpp index 3c00ee7..6ed1d85 100644 --- a/project/components/parser.cpp +++ b/project/components/parser.cpp @@ -137,7 +137,7 @@ void init() ); fixed_arena_init(defines_map_arena); - defines = HashTable::init_reserve( allocator_info(defines_map_arena), 256 ); + defines = hashtable_init_reserve( allocator_info(defines_map_arena), 256 ); } internal diff --git a/project/dependencies/containers.hpp b/project/dependencies/containers.hpp index e6ec2d8..948c0d1 100644 --- a/project/dependencies/containers.hpp +++ b/project/dependencies/containers.hpp @@ -352,6 +352,28 @@ bool set_capacity(Array& array, usize new_capacity) Data = rcast(Type*, new_header + 1); return true; } + +#define array_init(Type, allocator) array_init(allocator) +#define array_init(Type, allocator) array_init(allocator) +#define array_init_reserve(Type, allocator, capacity) array_init_reserve(allocator, capacity) +#define array_append(Type, array, other) append(array, other) +#define array_append_value(Type, array, value) append(array, value) +#define array_append_items(Type, array, items, item_num) append(array, items, item_num) +#define array_append_at(Type, array, item, idx) append_at(array, item, idx) +#define array_append_items_at(Type, array, items, num, idx) append_at(array, items, num, idx) +#define array_back(Type, array) back(array) +#define array_clear(Type, array) clear(array) +#define array_fill(Type, array, begin, end, value) fill(array, begin, end, value) +#define array_free(Type, array) free(array) +#define array_grow(Type, array, min_capacity) grow(array, min_capacity) +#define array_num(Type, array) num(array) +#define array_pop(Type, array) pop(array) +#define array_remove_at(Type, array, idx) remove_at(array, idx) +#define array_reserve(Type, array, new_capacity) reserve(array, new_capacity) +#define array_resize(Type, array, num) resize(array, num) +#define array_set_capacity(Type, array, new_capacity) set_capacity(array, new_capacity) +#define array_get_header(array) get_header(array) + #pragma endregion Array // TODO(Ed) : This thing needs ALOT of work. @@ -372,7 +394,8 @@ struct HashTableEntry { Type Value; }; -// Forward declarations for all lifted functions +#define HashTableEntry(Type) HashTableEntry + template HashTable hashtable_init(AllocatorInfo allocator); template HashTable hashtable_init_reserve(AllocatorInfo allocator, usize num); template void clear(HashTable& table); @@ -399,7 +422,7 @@ struct HashTable Array Hashes; Array> Entries; -#if 1 +#if GEN_SUPPORT_CPP_MEMBER_FEATURES #pragma region Member Mapping forceinline static HashTable init(AllocatorInfo allocator) { return GEN_NS hashtable_init(allocator); } forceinline static HashTable init_reserve(AllocatorInfo allocator, usize num) { return GEN_NS hashtable_init_reserve(allocator, num); } @@ -634,6 +657,25 @@ bool full(HashTable& table) { b32 result = num(table.Entries) > critical_load; return result; } + +#define hashtable_init(Type, allocator) hashtable_init(allocator) +#define hashtable_init_reserve(Type, allocator, num) hashtable_init_reserve(allocator, num) +#define hashtable_clear(Type, table) clear(table) +#define hashtable_destroy(Type, table) destroy(table) +#define hashtable_get(Type, table, key) get(table, key) +#define hashtable_grow(Type, table) grow(table) +#define hashtable_rehash(Type, table, new_num) rehash(table, new_num) +#define hashtable_rehash_fast(Type, table) rehash_fast(table) +#define hashtable_remove(Type, table, key) remove(table, key) +#define hashtable_remove_entry(Type, table, idx) remove_entry(table, idx) +#define hashtable_set(Type, table, key, value) set(table, key, value) +#define hashtable_slot(Type, table, key) slot(table, key) +#define hashtable_add_entry(Type, table, key) add_entry(table, key) +#define hashtable_find(Type, table, key) find(table, key) +#define hashtable_full(Type, table) full(table) +#define hashtable_map(Type, table, map_proc) map(table, map_proc) +#define hashtable_map_mut(Type, table, map_proc) map_mut(table, map_proc) + #pragma endregion HashTable #pragma endregion Containers diff --git a/project/dependencies/parsing.cpp b/project/dependencies/parsing.cpp index c314218..eee923e 100644 --- a/project/dependencies/parsing.cpp +++ b/project/dependencies/parsing.cpp @@ -447,7 +447,7 @@ char* adt_parse_number_strict( ADT_Node* node, char* base_str ) while ( *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; } @@ -476,7 +476,7 @@ char* adt_parse_number( ADT_Node* node, char* base_str ) u8 node_props = 0; /* 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; } @@ -552,7 +552,7 @@ char* adt_parse_number( ADT_Node* node, char* base_str ) char expbuf[ 6 ] = { 0 }; ssize expi = 0; - if ( *e && ! ! str_find( "eE", *e ) ) + if ( *e && ! ! char_first_occurence( "eE", *e ) ) { ++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 ); _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 ); p++; diff --git a/project/dependencies/platform.hpp b/project/dependencies/platform.hpp index ca837af..e1e358f 100644 --- a/project/dependencies/platform.hpp +++ b/project/dependencies/platform.hpp @@ -1,4 +1,4 @@ -#define GEN_SUPPORT_CPP_MEMBER_FEATURES 1 +#define GEN_SUPPORT_CPP_MEMBER_FEATURES 0 #ifdef GEN_INTELLISENSE_DIRECTIVES # pragma once diff --git a/project/dependencies/string_ops.hpp b/project/dependencies/string_ops.hpp index fe922ac..dc76b51 100644 --- a/project/dependencies/string_ops.hpp +++ b/project/dependencies/string_ops.hpp @@ -6,7 +6,6 @@ #pragma region String Ops 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_alphanumeric( char c );