summaryrefslogtreecommitdiffstats
path: root/src/core/templates.h
diff options
context:
space:
mode:
authorNikolay Korolev <nickvnuk@gmail.com>2020-12-06 17:30:51 +0100
committerNikolay Korolev <nickvnuk@gmail.com>2020-12-06 17:30:51 +0100
commitfe918d41c249205754a48010a9d69cfd25b406ff (patch)
tree210d0637ff37875183483aae2dcedbf146b7bf55 /src/core/templates.h
parentlil fix (diff)
downloadre3-fe918d41c249205754a48010a9d69cfd25b406ff.tar
re3-fe918d41c249205754a48010a9d69cfd25b406ff.tar.gz
re3-fe918d41c249205754a48010a9d69cfd25b406ff.tar.bz2
re3-fe918d41c249205754a48010a9d69cfd25b406ff.tar.lz
re3-fe918d41c249205754a48010a9d69cfd25b406ff.tar.xz
re3-fe918d41c249205754a48010a9d69cfd25b406ff.tar.zst
re3-fe918d41c249205754a48010a9d69cfd25b406ff.zip
Diffstat (limited to 'src/core/templates.h')
-rw-r--r--src/core/templates.h20
1 files changed, 13 insertions, 7 deletions
diff --git a/src/core/templates.h b/src/core/templates.h
index 9f5bd5ea..bb89814e 100644
--- a/src/core/templates.h
+++ b/src/core/templates.h
@@ -123,13 +123,19 @@ public:
return m_flags[handle>>8].u == (handle & 0xFF) ?
(T*)&m_entries[handle >> 8] : nil;
}
- int GetIndex(T *entry){
- int i = GetJustIndex(entry);
- return m_flags[i].u + (i<<8);
- }
- int GetJustIndex(T *entry){
- // TODO: the cast is unsafe
- return (int)((U*)entry - m_entries);
+ int GetIndex(T* entry) {
+ int i = GetJustIndex_NoFreeAssert(entry);
+ return m_flags[i].u + (i << 8);
+ }
+ int GetJustIndex(T* entry) {
+ int index = GetJustIndex_NoFreeAssert(entry);
+ assert(!IsFreeSlot(index));
+ return index;
+ }
+ int GetJustIndex_NoFreeAssert(T* entry) {
+ int index = ((U*)entry - m_entries);
+ assert((U*)entry == (U*)&m_entries[index]); // cast is unsafe - check required
+ return index;
}
int GetNoOfUsedSpaces(void) const {
int i;