From 591f8737a5619207e192a2fcf5cf6a7aee8eaa0a Mon Sep 17 00:00:00 2001 From: turleypol Date: Wed, 3 Jan 2024 22:54:24 +0100 Subject: [PATCH] remaining bscript, started plib --- .../bscript/compiler/file/SourceFileCache.cpp | 14 ++----------- pol-core/bscript/expression.cpp | 6 ++---- pol-core/plib/RawMap.cpp | 7 ++++--- pol-core/plib/fsa.h | 20 +++++++++---------- 4 files changed, 17 insertions(+), 30 deletions(-) diff --git a/pol-core/bscript/compiler/file/SourceFileCache.cpp b/pol-core/bscript/compiler/file/SourceFileCache.cpp index 7c3cdccde5..fec451150d 100644 --- a/pol-core/bscript/compiler/file/SourceFileCache.cpp +++ b/pol-core/bscript/compiler/file/SourceFileCache.cpp @@ -1,10 +1,10 @@ #include "SourceFileCache.h" -#include "clib/logfacility.h" -#include "clib/timer.h" #include "bscript/compiler/Profile.h" #include "bscript/compiler/file/SourceFile.h" #include "bscript/compiler/file/SourceFileIdentifier.h" +#include "clib/logfacility.h" +#include "clib/timer.h" namespace Pol::Bscript::Compiler { @@ -26,7 +26,6 @@ std::shared_ptr SourceFileCache::load( const SourceFileIdentifier& i auto itr = files.find( pathname ); if ( itr != files.end() ) { - // INFO_PRINT << "Cache hit: " << pathname << "\n"; profile.cache_hits++; // We do not propagate errors here. This happens when the compilation unit @@ -34,7 +33,6 @@ std::shared_ptr SourceFileCache::load( const SourceFileIdentifier& i // whether the file was just loaded, or was cached. return ( *itr ).second; } - // INFO_PRINT << "Cache miss: " << pathname << "\n"; profile.cache_misses++; } @@ -83,18 +81,10 @@ void SourceFileCache::keep_some() for ( auto itr = pathname_frequencies.begin(), end = itr + remove; itr != end; ++itr ) { const std::string& pathname = *( ( *itr ).second ); - // INFO_PRINT << "Remove from cache: " << *( *itr ).second - // << "(" << ( *itr ).first << ")\n"; ( *itr ).second = nullptr; files.erase( pathname ); } profile.prune_cache_delete_micros += delete_timer.ellapsed().count(); - - // INFO_PRINT << "Cache kept:\n"; - // for( auto& kv : files ) - // { - // INFO_PRINT << " - " << kv.first << " (" << frequency[kv.first] << ")\n"; - // } } } // namespace Pol::Bscript::Compiler diff --git a/pol-core/bscript/expression.cpp b/pol-core/bscript/expression.cpp index de34d33e19..6d55898a3b 100644 --- a/pol-core/bscript/expression.cpp +++ b/pol-core/bscript/expression.cpp @@ -705,13 +705,11 @@ void Expression::remove_non_emitting_tokens() void Expression::dump_tokens() const { - INFO_PRINT << "Expression with " << tokens.size() << " tokens:\n"; + INFO_PRINT2( "Expression with {} tokens:", tokens.size() ); for ( unsigned i = 0; i < tokens.size(); ++i ) { Token* tk = tokens[i]; - INFO_PRINT << fmt::pad( i, 4, ' ' ) - << " (" << fmt::pad( get_num_tokens( i ), 2, ' ' ) << ")" - << ": " << *tk << "\n"; + INFO_PRINT2( "{:>4} ({:>2}): {}", i, get_num_tokens( i ), *tk ); } } diff --git a/pol-core/plib/RawMap.cpp b/pol-core/plib/RawMap.cpp index 7fdcbbfe30..55ae9c3dc2 100644 --- a/pol-core/plib/RawMap.cpp +++ b/pol-core/plib/RawMap.cpp @@ -104,7 +104,8 @@ unsigned int RawMap::load_full_map( FILE* mapfile, FILE* mapdif_file ) // TODO: cleanup the code unsigned int RawMap::load_full_map( int uo_mapid, std::istream& ifs ) { - auto maphash = []( int mapid, size_t chunkidx ) { + auto maphash = []( int mapid, size_t chunkidx ) + { char mapstring[1024]; snprintf( mapstring, sizeof mapstring, "build/map%dlegacymul/%08i.dat", mapid, (int)chunkidx ); return HashLittle2( mapstring ); @@ -145,8 +146,8 @@ unsigned int RawMap::load_full_map( int uo_mapid, std::istream& ifs ) } while ( currentblock != nullptr && filemap.size() < uopfile.header()->nfiles() ); if ( uopfile.header()->nfiles() != filemap.size() ) - INFO_PRINT << "Warning: not all chunks read (" << filemap.size() << "/" - << uopfile.header()->nfiles() << ")\n"; + INFO_PRINT2( "Warning: not all chunks read ({}/{})", filemap.size(), + uopfile.header()->nfiles() ); // Sanity checking and pre-allocate mapinfo vector passert_r( diff --git a/pol-core/plib/fsa.h b/pol-core/plib/fsa.h index 6fbc7d2557..5b1048d034 100644 --- a/pol-core/plib/fsa.h +++ b/pol-core/plib/fsa.h @@ -89,7 +89,7 @@ class FixedSizeAllocator ~FixedSizeAllocator() { // Free up the memory - delete[]( char* ) m_pMemory; + delete[] (char*)m_pMemory; } // Allocate a new USER_TYPE and return a pointer to it @@ -178,28 +178,26 @@ class FixedSizeAllocator // For debugging this displays both lists (using the prev/next list pointers) void Debug() { - INFO_PRINT << "free list"; + INFO_PRINT2( "free list" ); FSA_ELEMENT* p = m_pFirstFree; - fmt::Writer _tmp; + std::string tmp; while ( p ) { - _tmp << fmt::hex( p->pPrev ) << "!" << fmt::hex( p->pNext ) << " "; + tmp += fmt::format( "{:#x}!{:#x} ", p->pPrev, p->pNext ); p = p->pNext; } - _tmp << "\n"; - INFO_PRINT << _tmp.str(); + INFO_PRINT2( tmp ); - INFO_PRINT << "used list\n"; - _tmp.Clear(); + INFO_PRINT2( "used list" ); + tmp.clear(); p = m_pFirstUsed; while ( p ) { - _tmp << fmt::hex( p->pPrev ) << "!" << fmt::hex( p->pNext ) << " "; + tmp += fmt::format( "{:#x}!{:#x} ", p->pPrev, p->pNext ); p = p->pNext; } - _tmp << "\n"; - INFO_PRINT << _tmp.str(); + INFO_PRINT2( tmp ); } // Iterators