mirror of
https://github.com/libretro/scummvm.git
synced 2025-01-24 19:45:07 +00:00
SCI: Improved the Table template a bit by taking advantage of C++ features
svn-id: r40190
This commit is contained in:
parent
d62b4c62c4
commit
ed914d6740
@ -247,7 +247,7 @@ byte *kmem(EngineState *s, reg_t handle) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
return (byte *) ht->table[handle.offset].entry.mem;
|
||||
return (byte *)ht->table[handle.offset].mem;
|
||||
}
|
||||
|
||||
// Frees the specified handle. Returns 0 on success, 1 otherwise.
|
||||
|
@ -53,7 +53,7 @@ Node *lookup_node(EngineState *s, reg_t addr, const char *file, int line) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
return &(nt->table[addr.offset].entry);
|
||||
return &(nt->table[addr.offset]);
|
||||
}
|
||||
|
||||
List *lookup_list(EngineState *s, reg_t addr, const char *file, int line) {
|
||||
@ -73,7 +73,7 @@ List *lookup_list(EngineState *s, reg_t addr, const char *file, int line) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
return &(lt->table[addr.offset].entry);
|
||||
return &(lt->table[addr.offset]);
|
||||
}
|
||||
|
||||
#ifdef DISABLE_VALIDATIONS
|
||||
|
@ -288,16 +288,7 @@ static void sync_Object(Common::Serializer &s, Object &obj) {
|
||||
}
|
||||
|
||||
static void sync_Clone(Common::Serializer &s, Clone &obj) {
|
||||
s.syncAsSint32LE(obj.flags);
|
||||
sync_reg_t(s, obj.pos);
|
||||
s.syncAsSint32LE(obj.variables_nr);
|
||||
s.syncAsSint32LE(obj.variable_names_nr);
|
||||
s.syncAsSint32LE(obj.methods_nr);
|
||||
|
||||
if (!obj.variables && obj.variables_nr)
|
||||
obj.variables = (reg_t *)sci_calloc(obj.variables_nr, sizeof(reg_t));
|
||||
for (int i = 0; i < obj.variables_nr; ++i)
|
||||
sync_reg_t(s, obj.variables[i]);
|
||||
sync_Object(s, obj);
|
||||
}
|
||||
|
||||
static void sync_List(Common::Serializer &s, List &obj) {
|
||||
@ -312,9 +303,9 @@ static void sync_Node(Common::Serializer &s, Node &obj) {
|
||||
sync_reg_t(s, obj.value);
|
||||
}
|
||||
|
||||
static void sync_CloneEntry(Common::Serializer &s, CloneEntry &obj) {
|
||||
static void sync_CloneEntry(Common::Serializer &s, CloneTable::Entry &obj) {
|
||||
s.syncAsSint32LE(obj.next_free);
|
||||
sync_Clone(s, obj.entry);
|
||||
sync_Clone(s, obj);
|
||||
}
|
||||
|
||||
static void sync_CloneTable(Common::Serializer &s, CloneTable &obj) {
|
||||
@ -324,14 +315,14 @@ static void sync_CloneTable(Common::Serializer &s, CloneTable &obj) {
|
||||
s.syncAsSint32LE(obj.max_entry);
|
||||
|
||||
if (!obj.table && obj.entries_nr)
|
||||
obj.table = (CloneEntry *)sci_calloc(obj.entries_nr, sizeof(CloneEntry));
|
||||
obj.table = (CloneTable::Entry *)sci_calloc(obj.entries_nr, sizeof(CloneTable::Entry));
|
||||
for (int i = 0; i < obj.entries_nr; ++i)
|
||||
sync_CloneEntry(s, obj.table[i]);
|
||||
}
|
||||
|
||||
static void sync_ListEntry(Common::Serializer &s, ListEntry &obj) {
|
||||
static void sync_ListEntry(Common::Serializer &s, ListTable::Entry &obj) {
|
||||
s.syncAsSint32LE(obj.next_free);
|
||||
sync_List(s, obj.entry);
|
||||
sync_List(s, obj);
|
||||
}
|
||||
|
||||
static void sync_ListTable(Common::Serializer &s, ListTable &obj) {
|
||||
@ -341,14 +332,14 @@ static void sync_ListTable(Common::Serializer &s, ListTable &obj) {
|
||||
s.syncAsSint32LE(obj.max_entry);
|
||||
|
||||
if (!obj.table && obj.entries_nr)
|
||||
obj.table = (ListEntry *)sci_calloc(obj.entries_nr, sizeof(ListEntry));
|
||||
obj.table = (ListTable::Entry *)sci_calloc(obj.entries_nr, sizeof(ListTable::Entry));
|
||||
for (int i = 0; i < obj.entries_nr; ++i)
|
||||
sync_ListEntry(s, obj.table[i]);
|
||||
}
|
||||
|
||||
static void sync_NodeEntry(Common::Serializer &s, NodeEntry &obj) {
|
||||
static void sync_NodeEntry(Common::Serializer &s, NodeTable::Entry &obj) {
|
||||
s.syncAsSint32LE(obj.next_free);
|
||||
sync_Node(s, obj.entry);
|
||||
sync_Node(s, obj);
|
||||
}
|
||||
|
||||
static void sync_NodeTable(Common::Serializer &s, NodeTable &obj) {
|
||||
@ -358,7 +349,7 @@ static void sync_NodeTable(Common::Serializer &s, NodeTable &obj) {
|
||||
s.syncAsSint32LE(obj.max_entry);
|
||||
|
||||
if (!obj.table && obj.entries_nr)
|
||||
obj.table = (NodeEntry *)sci_calloc(obj.entries_nr, sizeof(NodeEntry));
|
||||
obj.table = (NodeTable::Entry *)sci_calloc(obj.entries_nr, sizeof(NodeTable::Entry));
|
||||
for (int i = 0; i < obj.entries_nr; ++i)
|
||||
sync_NodeEntry(s, obj.table[i]);
|
||||
}
|
||||
@ -486,7 +477,7 @@ static void sync_MemObjPtr(Common::Serializer &s, MemObject *&obj) {
|
||||
break;
|
||||
case MEM_OBJ_HUNK:
|
||||
if (s.isLoading()) {
|
||||
init_Hunk_table(&obj->data.hunks);
|
||||
obj->data.hunks.initTable();
|
||||
}
|
||||
break;
|
||||
case MEM_OBJ_STRING_FRAG:
|
||||
@ -501,7 +492,7 @@ static void sync_MemObjPtr(Common::Serializer &s, MemObject *&obj) {
|
||||
sync_DynMem(s, obj->data.dynmem);
|
||||
break;
|
||||
default:
|
||||
error("Unknown MemObject type %d\n", obj->type);
|
||||
error("Unknown MemObject type %d", obj->type);
|
||||
break;
|
||||
}
|
||||
}
|
||||
@ -590,7 +581,7 @@ static void reconstruct_stack(EngineState *retval) {
|
||||
static int clone_entry_used(CloneTable *table, int n) {
|
||||
int backup;
|
||||
int seeker = table->first_free;
|
||||
CloneEntry *entries = table->table;
|
||||
CloneTable::Entry *entries = table->table;
|
||||
|
||||
if (seeker == HEAPENTRY_INVALID) return 1;
|
||||
|
||||
@ -715,7 +706,7 @@ static void reconstruct_clones(EngineState *s, SegManager *self) {
|
||||
switch (mobj->type) {
|
||||
case MEM_OBJ_CLONES: {
|
||||
int j;
|
||||
CloneEntry *seeker = mobj->data.clones.table;
|
||||
CloneTable::Entry *seeker = mobj->data.clones.table;
|
||||
|
||||
/*
|
||||
sciprintf("Free list: ");
|
||||
@ -726,7 +717,7 @@ static void reconstruct_clones(EngineState *s, SegManager *self) {
|
||||
|
||||
sciprintf("Entries w/zero vars: ");
|
||||
for (j = 0; j < mobj->data.clones.max_entry; j++) {
|
||||
if (mobj->data.clones.table[j].entry.variables == NULL)
|
||||
if (mobj->data.clones.table[j].variables == NULL)
|
||||
sciprintf("%d ", j);
|
||||
}
|
||||
sciprintf("\n");
|
||||
@ -739,17 +730,17 @@ static void reconstruct_clones(EngineState *s, SegManager *self) {
|
||||
seeker++;
|
||||
continue;
|
||||
}
|
||||
base_obj = obj_get(s, seeker->entry.variables[SCRIPT_SPECIES_SELECTOR]);
|
||||
base_obj = obj_get(s, seeker->variables[SCRIPT_SPECIES_SELECTOR]);
|
||||
if (!base_obj) {
|
||||
sciprintf("Clone entry without a base class: %d\n", j);
|
||||
seeker->entry.base = seeker->entry.base_obj = NULL;
|
||||
seeker->entry.base_vars = seeker->entry.base_method = NULL;
|
||||
seeker->base = seeker->base_obj = NULL;
|
||||
seeker->base_vars = seeker->base_method = NULL;
|
||||
continue;
|
||||
}
|
||||
seeker->entry.base = base_obj->base;
|
||||
seeker->entry.base_obj = base_obj->base_obj;
|
||||
seeker->entry.base_vars = base_obj->base_vars;
|
||||
seeker->entry.base_method = base_obj->base_method;
|
||||
seeker->base = base_obj->base;
|
||||
seeker->base_obj = base_obj->base_obj;
|
||||
seeker->base_vars = base_obj->base_vars;
|
||||
seeker->base_method = base_obj->base_method;
|
||||
|
||||
seeker++;
|
||||
}
|
||||
|
@ -328,7 +328,7 @@ int parse_reg_t(EngineState *s, const char *str, reg_t *dest) { // Returns 0 on
|
||||
obj = mobj->data.script.objects + idx;
|
||||
objpos.offset = obj->pos.offset;
|
||||
} else if (mobj->type == MEM_OBJ_CLONES) {
|
||||
obj = &(mobj->data.clones.table[idx].entry);
|
||||
obj = &(mobj->data.clones.table[idx]);
|
||||
objpos.offset = idx;
|
||||
valid = clone_is_used(&mobj->data.clones, idx);
|
||||
}
|
||||
|
@ -366,7 +366,7 @@ static void print_list(EngineState *s, List *l) {
|
||||
return;
|
||||
}
|
||||
|
||||
node = &(mobj->data.nodes.table[pos.offset].entry);
|
||||
node = &(mobj->data.nodes.table[pos.offset]);
|
||||
|
||||
sciprintf("\t"PREG" : "PREG" -> "PREG"\n", PRINT_REG(pos), PRINT_REG(node->key), PRINT_REG(node->value));
|
||||
|
||||
@ -446,7 +446,7 @@ static void _c_single_seg_info(EngineState *s, MemObject *mobj) {
|
||||
for (i = 0; i < ct->max_entry; i++)
|
||||
if (ENTRY_IS_VALID(ct, i)) {
|
||||
sciprintf(" [%04x] ", i);
|
||||
print_obj_head(s, &(ct->table[i].entry));
|
||||
print_obj_head(s, &(ct->table[i]));
|
||||
}
|
||||
}
|
||||
break;
|
||||
@ -459,7 +459,7 @@ static void _c_single_seg_info(EngineState *s, MemObject *mobj) {
|
||||
for (i = 0; i < lt->max_entry; i++)
|
||||
if (ENTRY_IS_VALID(lt, i)) {
|
||||
sciprintf(" [%04x]: ", i);
|
||||
print_list(s, &(lt->table[i].entry));
|
||||
print_list(s, &(lt->table[i]));
|
||||
}
|
||||
}
|
||||
break;
|
||||
@ -477,7 +477,7 @@ static void _c_single_seg_info(EngineState *s, MemObject *mobj) {
|
||||
for (i = 0; i < ht->max_entry; i++)
|
||||
if (ENTRY_IS_VALID(ht, i)) {
|
||||
sciprintf(" [%04x] %d bytes at %p, type=%s\n",
|
||||
i, ht->table[i].entry.size, ht->table[i].entry.mem, ht->table[i].entry.type);
|
||||
i, ht->table[i].size, ht->table[i].mem, ht->table[i].type);
|
||||
}
|
||||
}
|
||||
|
||||
@ -512,7 +512,7 @@ static int show_node(EngineState *s, reg_t addr) {
|
||||
return 1;
|
||||
}
|
||||
|
||||
list = &(lt->table[addr.offset].entry);
|
||||
list = &(lt->table[addr.offset]);
|
||||
|
||||
sciprintf(PREG" : first x last = ("PREG", "PREG")\n", PRINT_REG(addr), PRINT_REG(list->first), PRINT_REG(list->last));
|
||||
} else {
|
||||
@ -531,7 +531,7 @@ static int show_node(EngineState *s, reg_t addr) {
|
||||
sciprintf("Address does not contain a node\n");
|
||||
return 1;
|
||||
}
|
||||
node = &(nt->table[addr.offset].entry);
|
||||
node = &(nt->table[addr.offset]);
|
||||
|
||||
sciprintf(PREG" : prev x next = ("PREG", "PREG"); maps "PREG" -> "PREG"\n",
|
||||
PRINT_REG(addr), PRINT_REG(node->pred), PRINT_REG(node->succ), PRINT_REG(node->key), PRINT_REG(node->value));
|
||||
|
@ -363,7 +363,7 @@ int SegManager::deallocateScript(int script_nr) {
|
||||
}
|
||||
|
||||
MemObject *SegManager::memObjAllocate(SegmentId segid, int hash_id, memObjType type) {
|
||||
MemObject *mem = (MemObject *)sci_calloc(sizeof(MemObject), 1);
|
||||
MemObject *mem = (MemObject *)sci_calloc(1, sizeof(MemObject));
|
||||
if (!mem) {
|
||||
sciprintf("SegManager: invalid mem_obj ");
|
||||
return NULL;
|
||||
@ -1283,96 +1283,46 @@ Hunk *SegManager::alloc_hunk_entry(const char *hunk_type, int size, reg_t *reg)
|
||||
}
|
||||
|
||||
|
||||
void init_List_table(ListTable *table) {
|
||||
table->entries_nr = 8;
|
||||
table->max_entry = 0;
|
||||
table->entries_used = 0;
|
||||
table->first_free = HEAPENTRY_INVALID;
|
||||
table->table = (ListEntry *)sci_malloc(sizeof(ListEntry) * 8);
|
||||
memset(table->table, 0, sizeof(ListEntry) * 8);
|
||||
}
|
||||
|
||||
void free_List_entry(ListTable *table, int index) {
|
||||
ListEntry *e = table->table + index;
|
||||
|
||||
if (index < 0 || index >= table->max_entry) {
|
||||
error("heapmgr: Attempt to release invalid table index %d", index);
|
||||
}
|
||||
|
||||
e->next_free = table->first_free;
|
||||
table->table[index].next_free = table->first_free;
|
||||
table->first_free = index;
|
||||
table->entries_used--;
|
||||
}
|
||||
|
||||
|
||||
|
||||
void init_Node_table(NodeTable *table) {
|
||||
table->entries_nr = 32;
|
||||
table->max_entry = 0;
|
||||
table->entries_used = 0;
|
||||
table->first_free = HEAPENTRY_INVALID;
|
||||
table->table = (NodeEntry *)sci_malloc(sizeof(NodeEntry) * 32);
|
||||
memset(table->table, 0, sizeof(NodeEntry) * 32);
|
||||
}
|
||||
|
||||
void free_Node_entry(NodeTable *table, int index) {
|
||||
NodeEntry *e = table->table + index;
|
||||
|
||||
if (index < 0 || index >= table->max_entry) {
|
||||
error("heapmgr: Attempt to release invalid table index %d", index);
|
||||
}
|
||||
|
||||
e->next_free = table->first_free;
|
||||
table->table[index].next_free = table->first_free;
|
||||
table->first_free = index;
|
||||
table->entries_used--;
|
||||
}
|
||||
|
||||
|
||||
|
||||
void init_Clone_table(CloneTable *table) {
|
||||
table->entries_nr = 16;
|
||||
table->max_entry = 0;
|
||||
table->entries_used = 0;
|
||||
table->first_free = HEAPENTRY_INVALID;
|
||||
table->table = (CloneEntry *)sci_malloc(sizeof(CloneEntry) * 16);
|
||||
memset(table->table, 0, sizeof(CloneEntry) * 16);
|
||||
}
|
||||
|
||||
void free_Clone_entry(CloneTable *table, int index) {
|
||||
CloneEntry *e = table->table + index;
|
||||
|
||||
if (index < 0 || index >= table->max_entry) {
|
||||
error("heapmgr: Attempt to release invalid table index %d", index);
|
||||
}
|
||||
|
||||
free(e->entry.variables); // Free the dynamically allocated memory part
|
||||
free(table->table[index].variables); // Free the dynamically allocated memory part
|
||||
|
||||
e->next_free = table->first_free;
|
||||
table->table[index].next_free = table->first_free;
|
||||
table->first_free = index;
|
||||
table->entries_used--;
|
||||
}
|
||||
|
||||
|
||||
|
||||
void init_Hunk_table(HunkTable *table) {
|
||||
table->entries_nr = 4;
|
||||
table->max_entry = 0;
|
||||
table->entries_used = 0;
|
||||
table->first_free = HEAPENTRY_INVALID;
|
||||
table->table = (HunkEntry *)sci_malloc(sizeof(HunkEntry) * 4);
|
||||
memset(table->table, 0, sizeof(HunkEntry) * 4);
|
||||
}
|
||||
|
||||
void free_Hunk_entry(HunkTable *table, int index) {
|
||||
HunkEntry *e = table->table + index;
|
||||
|
||||
if (index < 0 || index >= table->max_entry) {
|
||||
error("heapmgr: Attempt to release invalid table index %d", index);
|
||||
}
|
||||
|
||||
free(e->entry.mem);
|
||||
free(table->table[index].mem);
|
||||
|
||||
e->next_free = table->first_free;
|
||||
table->table[index].next_free = table->first_free;
|
||||
table->first_free = index;
|
||||
table->entries_used--;
|
||||
}
|
||||
@ -1386,7 +1336,7 @@ Clone *SegManager::alloc_Clone(reg_t *addr) {
|
||||
|
||||
if (!Clones_seg_id) {
|
||||
mobj = allocNonscriptSegment(MEM_OBJ_CLONES, &(Clones_seg_id));
|
||||
init_Clone_table(&(mobj->data.clones));
|
||||
mobj->data.clones.initTable();
|
||||
} else
|
||||
mobj = heap[Clones_seg_id];
|
||||
|
||||
@ -1394,7 +1344,7 @@ Clone *SegManager::alloc_Clone(reg_t *addr) {
|
||||
offset = table->allocEntry();
|
||||
|
||||
*addr = make_reg(Clones_seg_id, offset);
|
||||
return &(mobj->data.clones.table[offset].entry);
|
||||
return &(mobj->data.clones.table[offset]);
|
||||
}
|
||||
|
||||
List *SegManager::alloc_List(reg_t *addr) {
|
||||
@ -1404,7 +1354,7 @@ List *SegManager::alloc_List(reg_t *addr) {
|
||||
|
||||
if (!Lists_seg_id) {
|
||||
mobj = allocNonscriptSegment(MEM_OBJ_LISTS, &(Lists_seg_id));
|
||||
init_List_table(&(mobj->data.lists));
|
||||
mobj->data.lists.initTable();
|
||||
} else
|
||||
mobj = heap[Lists_seg_id];
|
||||
|
||||
@ -1412,7 +1362,7 @@ List *SegManager::alloc_List(reg_t *addr) {
|
||||
offset = table->allocEntry();
|
||||
|
||||
*addr = make_reg(Lists_seg_id, offset);
|
||||
return &(mobj->data.lists.table[offset].entry);
|
||||
return &(mobj->data.lists.table[offset]);
|
||||
}
|
||||
|
||||
Node *SegManager::alloc_Node(reg_t *addr) {
|
||||
@ -1422,7 +1372,7 @@ Node *SegManager::alloc_Node(reg_t *addr) {
|
||||
|
||||
if (!Nodes_seg_id) {
|
||||
mobj = allocNonscriptSegment(MEM_OBJ_NODES, &(Nodes_seg_id));
|
||||
init_Node_table(&(mobj->data.nodes));
|
||||
mobj->data.nodes.initTable();
|
||||
} else
|
||||
mobj = heap[Nodes_seg_id];
|
||||
|
||||
@ -1430,7 +1380,7 @@ Node *SegManager::alloc_Node(reg_t *addr) {
|
||||
offset = table->allocEntry();
|
||||
|
||||
*addr = make_reg(Nodes_seg_id, offset);
|
||||
return &(mobj->data.nodes.table[offset].entry);
|
||||
return &(mobj->data.nodes.table[offset]);
|
||||
}
|
||||
|
||||
Hunk *SegManager::alloc_Hunk(reg_t *addr) {
|
||||
@ -1440,7 +1390,7 @@ Hunk *SegManager::alloc_Hunk(reg_t *addr) {
|
||||
|
||||
if (!Hunks_seg_id) {
|
||||
mobj = allocNonscriptSegment(MEM_OBJ_HUNK, &(Hunks_seg_id));
|
||||
init_Hunk_table(&(mobj->data.hunks));
|
||||
mobj->data.hunks.initTable();
|
||||
} else
|
||||
mobj = heap[Hunks_seg_id];
|
||||
|
||||
@ -1448,7 +1398,7 @@ Hunk *SegManager::alloc_Hunk(reg_t *addr) {
|
||||
offset = table->allocEntry();
|
||||
|
||||
*addr = make_reg(Hunks_seg_id, offset);
|
||||
return &(mobj->data.hunks.table[offset].entry);
|
||||
return &(mobj->data.hunks.table[offset]);
|
||||
}
|
||||
|
||||
|
||||
@ -1696,7 +1646,7 @@ void SegInterfaceClones::listAllOutgoingReferences(EngineState *s, reg_t addr, v
|
||||
return;
|
||||
}
|
||||
|
||||
clone = &(clone_table->table[addr.offset].entry);
|
||||
clone = &(clone_table->table[addr.offset]);
|
||||
|
||||
// Emit all member variables (including references to the 'super' delegate)
|
||||
for (i = 0; i < clone->variables_nr; i++)
|
||||
@ -1712,7 +1662,7 @@ void SegInterfaceClones::freeAtAddress(reg_t addr) {
|
||||
|
||||
assert(addr.segment == _segId);
|
||||
|
||||
victim_obj = &(_mobj->data.clones.table[addr.offset].entry);
|
||||
victim_obj = &(_mobj->data.clones.table[addr.offset]);
|
||||
|
||||
#ifdef GC_DEBUG
|
||||
if (!(victim_obj->flags & OBJECT_FLAG_FREED))
|
||||
@ -1826,7 +1776,7 @@ void SegInterfaceLists::listAllDeallocatable(void *param, NoteCallback note) {
|
||||
|
||||
void SegInterfaceLists::listAllOutgoingReferences(EngineState *s, reg_t addr, void *param, NoteCallback note) {
|
||||
ListTable *table = &(_mobj->data.lists);
|
||||
List *list = &(table->table[addr.offset].entry);
|
||||
List *list = &(table->table[addr.offset]);
|
||||
|
||||
if (!ENTRY_IS_VALID(table, addr.offset)) {
|
||||
fprintf(stderr, "Invalid list referenced for outgoing references: "PREG"\n", PRINT_REG(addr));
|
||||
@ -1860,7 +1810,7 @@ void SegInterfaceNodes::listAllDeallocatable(void *param, NoteCallback note) {
|
||||
|
||||
void SegInterfaceNodes::listAllOutgoingReferences(EngineState *s, reg_t addr, void *param, NoteCallback note) {
|
||||
NodeTable *table = &(_mobj->data.nodes);
|
||||
Node *node = &(table->table[addr.offset].entry);
|
||||
Node *node = &(table->table[addr.offset]);
|
||||
|
||||
if (!ENTRY_IS_VALID(table, addr.offset)) {
|
||||
fprintf(stderr, "Invalid node referenced for outgoing references: "PREG"\n", PRINT_REG(addr));
|
||||
|
@ -2089,7 +2089,7 @@ Object *obj_get(EngineState *s, reg_t offset) {
|
||||
|
||||
if (memobj != NULL) {
|
||||
if (memobj->type == MEM_OBJ_CLONES && ENTRY_IS_VALID(&memobj->data.clones, offset.offset))
|
||||
obj = &(memobj->data.clones.table[offset.offset].entry);
|
||||
obj = &(memobj->data.clones.table[offset.offset]);
|
||||
else if (memobj->type == MEM_OBJ_SCRIPT) {
|
||||
if (offset.offset <= memobj->data.script.buf_size && offset.offset >= -SCRIPT_OBJECT_MAGIC_OFFSET
|
||||
&& RAW_IS_OBJECT(memobj->data.script.buf + offset.offset)) {
|
||||
|
@ -259,12 +259,24 @@ struct Hunk {
|
||||
|
||||
template<typename T, int INITIAL, int INCREMENT>
|
||||
struct Table {
|
||||
struct Entry : public T {
|
||||
int next_free; /* Only used for free entries */
|
||||
};
|
||||
|
||||
int entries_nr; /* Number of entries allocated */
|
||||
int first_free; /* Beginning of a singly linked list for entries */
|
||||
int entries_used; /* Statistical information */
|
||||
int max_entry; /* Highest entry used */
|
||||
|
||||
T *table;
|
||||
Entry *table;
|
||||
|
||||
void initTable() {
|
||||
entries_nr = INITIAL;
|
||||
max_entry = 0;
|
||||
entries_used = 0;
|
||||
first_free = HEAPENTRY_INVALID;
|
||||
table = (Entry *)calloc(INITIAL, sizeof(Entry));
|
||||
}
|
||||
|
||||
int allocEntry() {
|
||||
entries_used++;
|
||||
@ -278,9 +290,8 @@ struct Table {
|
||||
if (max_entry == entries_nr) {
|
||||
entries_nr += INCREMENT;
|
||||
|
||||
table = (T *)sci_realloc(table,
|
||||
sizeof(T) * entries_nr);
|
||||
memset(&table[entries_nr-INCREMENT], 0, INCREMENT * sizeof(T));
|
||||
table = (Entry *)sci_realloc(table, sizeof(Entry) * entries_nr);
|
||||
memset(&table[entries_nr-INCREMENT], 0, INCREMENT * sizeof(Entry));
|
||||
}
|
||||
table[max_entry].next_free = max_entry; /* Tag as 'valid' */
|
||||
return max_entry++;
|
||||
@ -289,46 +300,22 @@ struct Table {
|
||||
};
|
||||
|
||||
/* CloneTable */
|
||||
struct CloneEntry {
|
||||
int next_free; /* Only used for free entries */
|
||||
Clone entry;
|
||||
};
|
||||
typedef Table<CloneEntry, 16, 4> CloneTable;
|
||||
void init_Clone_table(CloneTable *table);
|
||||
int alloc_Clone_entry(CloneTable *table);
|
||||
typedef Table<Clone, 16, 4> CloneTable;
|
||||
void free_Clone_entry(CloneTable *table, int index);
|
||||
|
||||
|
||||
/* NodeTable */
|
||||
struct NodeEntry {
|
||||
int next_free; /* Only used for free entries */
|
||||
Node entry;
|
||||
};
|
||||
typedef Table<NodeEntry, 32, 16> NodeTable;
|
||||
void init_Node_table(NodeTable *table);
|
||||
int alloc_Node_entry(NodeTable *table);
|
||||
typedef Table<Node, 32, 16> NodeTable;
|
||||
void free_Node_entry(NodeTable *table, int index);
|
||||
|
||||
|
||||
/* ListTable */
|
||||
struct ListEntry {
|
||||
int next_free; /* Only used for free entries */
|
||||
List entry;
|
||||
};
|
||||
typedef Table<ListEntry, 8, 4> ListTable;
|
||||
void init_List_table(ListTable *table);
|
||||
int alloc_List_entry(ListTable *table);
|
||||
typedef Table<List, 8, 4> ListTable;
|
||||
void free_List_entry(ListTable *table, int index);
|
||||
|
||||
|
||||
/* HunkTable */
|
||||
struct HunkEntry {
|
||||
int next_free; /* Only used for free entries */
|
||||
Hunk entry;
|
||||
};
|
||||
typedef Table<HunkEntry, 4, 4> HunkTable;
|
||||
void init_Hunk_table(HunkTable *table);
|
||||
int alloc_Hunk_entry(HunkTable *table);
|
||||
typedef Table<Hunk, 4, 4> HunkTable;
|
||||
void free_Hunk_entry(HunkTable *table, int index);
|
||||
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user