Use a string pool to reduce the memory footprint
git-svn-id: svn://svn.cc65.org/cc65/trunk@2197 b7a2c559-68d2-44c3-8de9-860c34a00d81
This commit is contained in:
@@ -43,6 +43,7 @@
|
||||
#include "error.h"
|
||||
#include "fileinfo.h"
|
||||
#include "objdata.h"
|
||||
#include "spool.h"
|
||||
|
||||
|
||||
|
||||
@@ -107,13 +108,27 @@ ObjData* NewObjData (void)
|
||||
|
||||
|
||||
|
||||
const char* GetObjString (const ObjData* O, unsigned long Index)
|
||||
void FreeObjStrings (ObjData* O)
|
||||
/* Free the module string data. Used once the object file is loaded completely
|
||||
* when all strings are converted to global strings.
|
||||
*/
|
||||
{
|
||||
while (O->StringCount) {
|
||||
xfree (O->Strings[--O->StringCount]);
|
||||
}
|
||||
xfree (O->Strings);
|
||||
O->Strings = 0;
|
||||
}
|
||||
|
||||
|
||||
|
||||
const char* GetObjString (const ObjData* O, unsigned Index)
|
||||
/* Get a string from the object file string table. Abort if the string index
|
||||
* is invalid.
|
||||
*/
|
||||
{
|
||||
if (Index >= O->StringCount) {
|
||||
Error ("Invalid string index (%lu) in module `%s'",
|
||||
Error ("Invalid string index (%u) in module `%s'",
|
||||
Index, GetObjFileName (O));
|
||||
}
|
||||
return O->Strings[Index];
|
||||
@@ -121,6 +136,18 @@ const char* GetObjString (const ObjData* O, unsigned long Index)
|
||||
|
||||
|
||||
|
||||
unsigned MakeGlobalStringId (const ObjData* O, unsigned Index)
|
||||
/* Convert a local string id into a global one and return it. */
|
||||
{
|
||||
if (Index >= O->StringCount) {
|
||||
Error ("Invalid string index (%u) in module `%s'",
|
||||
Index, GetObjFileName (O));
|
||||
}
|
||||
return GetStringId (O->Strings[Index]);
|
||||
}
|
||||
|
||||
|
||||
|
||||
const char* GetObjFileName (const ObjData* O)
|
||||
/* Get the name of the object file. Return "[linker generated]" if the object
|
||||
* file is NULL.
|
||||
|
||||
Reference in New Issue
Block a user